﻿#define PRINTF_SUPPORT_PTRDIFF_T
#define PRINTF_SUPPORT_LONG_LONG
#define PRINTF_SUPPORT_FLOAT
#define MEM_DEBUG
using Unicorn.Mips;
using System;
using Unicorn.Internal;
public unsafe class GlobalMembers: Uc
{
	public static app app_create(FILE tempFile, uint inSize)
	{
		int i = 0;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		//app tempApp = (app)malloc(sizeof(app));
		app tempApp = new app();
        if (tempApp == null)
		{
			return null;
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		//memset(tempApp, 0x00, sizeof(app));

		_app_ccdl* tempCCDL = (_app_ccdl*)malloc(sizeof(_app_ccdl));
		_app_impt* tempIMPT = (_app_impt*)malloc(sizeof(_app_impt));
        _app_expt* tempEXPT = (_app_expt*)malloc(sizeof(_app_expt));
        _app_rawd* tempRAWD = (_app_rawd*)malloc(sizeof(_app_rawd));

        fread(tempCCDL, sizeof(_app_ccdl), 1, tempFile);
		fread(tempIMPT, sizeof(_app_impt), 1, tempFile);
		fread(tempEXPT, sizeof(_app_expt), 1, tempFile);
		fread(tempRAWD, sizeof(_app_rawd), 1, tempFile);

		// read Import Table
		fseek(tempFile, tempIMPT->offset, SEEK_SET);
		_app_impt_entry* tempIHeader = (_app_impt_entry*)malloc(sizeof(_app_impt_entry));
        fread(tempIHeader, sizeof(_app_impt_entry), 1, tempFile);
		tempApp.import_count = tempIHeader->str_offset;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		_app_impt_entry* tempIEntry = (_app_impt_entry*)malloc(sizeof(_app_impt_entry) * tempApp.import_count);
		//if (tempIEntry == null)
		//{
		//	Debug.Assert(0);
		//}
		for (i = 0; i < tempApp.import_count; i++)
		{
			fread(tempIEntry+i, sizeof(_app_impt_entry), 1, tempFile);
		}

		tempApp.import_data = Arrays.InitializeWithDefaultInstances<app_import_entry>(tempApp.import_count);

		// read Import Strings
		for (i = 0; i < tempApp.import_count; i++)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
			//app_import_entry entry = (app_import_entry)malloc(sizeof(app_import_entry));
			app_import_entry* entry = (app_import_entry*)malloc(sizeof(app_import_entry));
            //if (entry == null)
            //{
            //	Debug.Assert(0);
            //}
            //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
            memset(entry, 0x00, sizeof(app_import_entry));
			entry->offset = tempIEntry[i].offset;

            //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
            //entry->name= (byte*)malloc(32);
			//if (entry.name == 0)
			//{
			//	Debug.Assert(0);
			//}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
			//memset(entry.name, 0x00, 32);
			for (int j = 0; j < 32; j++)
			{
				fread(entry->name+(j), 1, 1, tempFile);
				if (entry->name[j] == '\0')
				{
					int padding_len = (4 - ((j + 1) % 4)) % 4;
					fread(entry->name+(j) + 1, padding_len, 1, tempFile);
					break;
				}
			}

			tempApp.import_data[i] = *entry;

			Console.Write("import_data: offset 0x{0:x8}, name {1}\n", entry->offset, entry->name);
		}


		// read Export Table
		fseek(tempFile, tempEXPT->offset, SEEK_SET);
		_app_expt_entry* tempEHeader = (_app_expt_entry*)malloc(sizeof(_app_expt_entry));
        fread(tempEHeader, sizeof(_app_expt_entry), 1, tempFile);
		tempApp.export_count = tempEHeader->str_offset;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		_app_expt_entry* tempEEntry = (_app_expt_entry*)malloc(sizeof(_app_expt_entry) * tempApp.export_count);
		if (tempEEntry == null)
		{
			Debug.Assert(0);
		}
		for (i = 0; i < tempApp.export_count; i++)
		{
			fread(tempEEntry+i, sizeof(_app_expt_entry), 1, tempFile);
		}
		tempApp.export_data = Arrays.InitializeWithDefaultInstances<app_export_entry>(tempApp.export_count);
		// read Export Strings
		for (i = 0; i < tempApp.export_count; i++)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
			app_export_entry* entry = (app_export_entry*)malloc(sizeof(app_export_entry));
			if (entry == null)
			{
				Debug.Assert(0);
			}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
			memset(entry, 0x00, sizeof(app_export_entry));
			entry->offset = tempEEntry[i].offset;

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
			//entry.name = (string)malloc(32);
			//if (entry->name == 0)
			//{
			//	Debug.Assert(0);
			//}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
			memset(entry->name, 0x00, 32);
			for (int j = 0; j < 32; j++)
			{
				fread(entry->name+(j), 1, 1, tempFile);
				if (entry->name[j] == '\0')
				{
					int padding_len = (4 - ((j + 1) % 4)) % 4;
					fread(entry->name+(j) + 1, padding_len, 1, tempFile);
					break;
				}
			}

			tempApp.export_data[i] = *entry;

			Console.Write("export_data: offset 0x{0:x8}, name {1}\n", entry->offset, entry->name);
		}

		// read Binary Data
		fseek(tempFile, tempRAWD->offset, SEEK_SET);
		Console.Write("bin offset: offset 0x{0:x8} \n", tempRAWD->offset);
		tempApp.bin_size = tempRAWD->size;

		//4k ALIGN
		uint memory_align = (uint)(((tempRAWD->prog_size) + ((4096) - 1)) & ~((4096) - 1));
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		tempApp.bin_data = malloc(memory_align);
		if (tempApp.bin_data == null)
		{
			Debug.Assert(0);
		}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		memset(tempApp.bin_data, 0x00, memory_align);
		fread(tempApp.bin_data, tempApp.bin_size, 1, tempFile);

		tempApp.bin_size = memory_align;

		tempApp.bin_entry = tempRAWD->entry;
		tempApp.bin_bss = tempRAWD->prog_size - tempRAWD->size;
		tempApp.origin = tempRAWD->origin;
		tempApp.prog_size = tempRAWD->prog_size;

		return tempApp;
	}

    public static void app_delete(app inApp)
	{
		if (inApp == null)
		{
			return;
		}

		ushort i;

		if (inApp.import_data != null)
		{
			for (i = 0; i < inApp.import_count; i++)
			{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
				free(inApp.import_data[i]);
			}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
			free(inApp.import_data);
		}

		if (inApp.export_data != null)
		{
			for (i = 0; i < inApp.export_count; i++)
			{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
				free(inApp.export_data[i]);
			}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
			free(inApp.export_data);
		}

		if (inApp.bin_data != null)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
			free(inApp.bin_data);
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
		free(inApp);
	}

	public static bool app_import_add(app inApp, string inName, uint inOffset)
	{
		if ((inApp == null) || (inName == null))
		{
			return false;
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		app_import_entry* tempEntry = (app_import_entry*)malloc(sizeof(app_import_entry) + inName.Length + 1);
		if (tempEntry == null)
		{
			return false;
		}
		tempEntry->offset = inOffset;
		//tempEntry->name = (string)((ushort)tempEntry + sizeof(app_import_entry));
		//tempEntry->name = inName;

        for (int i = 0; i < inName .Length; i++)
        {
            tempEntry->name[i] = (byte)inName[i];
        }

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'realloc' has no equivalent in C#:
//		app_import_entry* tempRealloc = (app_import_entry)realloc(inApp.import_data, (sizeof(app_import_entry) * (inApp.import_count + 1)));
//		if (tempRealloc == null)
//		{
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
//			free(tempEntry);
//			return false;
//		}

		//inApp.import_data = tempRealloc;
		inApp.import_data = new app_import_entry[inApp.import_count + 1];
        inApp.import_data[inApp.import_count] = *tempEntry;
		inApp.import_count++;

		return true;
	}


    public static bool app_export_add(app inApp, string inName, uint inOffset)
	{
		if ((inApp == null) || (inName == null))
		{
			return false;
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		app_export_entry* tempEntry = (app_export_entry*)malloc(sizeof(app_export_entry) + inName.Length + 1);
		if (tempEntry == null)
		{
			return false;
		}
		tempEntry->offset = inOffset;
        //tempEntry.name = (string)((ushort)tempEntry + sizeof(app_export_entry));
        //tempEntry.name = inName;
        for (int i = 0; i < inName.Length; i++)
        {
            tempEntry->name[i] = (byte)inName[i];
        }
        //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'realloc' has no equivalent in C#:
        //		app_export_entry[] tempRealloc = (app_export_entry)realloc(inApp.export_data, (sizeof(app_export_entry) * (inApp.export_count + 1)));
        //		if (tempRealloc == null)
        //		{
        ////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
        //			free(tempEntry);
        //			return false;
        //		}

        //inApp.export_data = tempRealloc;
        inApp.export_data = new app_export_entry[inApp.export_count + 1];
        inApp.export_data[inApp.export_count] = *tempEntry;
		inApp.export_count++;

		return true;
	}

	/*public static bool app_save(app inApp, string inPath)
	{
		if ((inApp == null) || (inPath == null))
		{
			return false;
		}

		ushort i;

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_ccdl tempCCDL = _app_ccdl_default;
		_app_ccdl tempCCDL = new _app_ccdl(_app_ccdl_default);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_impt tempIMPT = _app_impt_default;
		_app_impt tempIMPT = new _app_impt(_app_impt_default);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_expt tempEXPT = _app_expt_default;
		_app_expt tempEXPT = new _app_expt(_app_expt_default);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_rawd tempRAWD = _app_rawd_default;
		_app_rawd tempRAWD = new _app_rawd(_app_rawd_default);

		uint[] tempPadding = {0, 0, 0, 0};

		tempIMPT.offset = sizeof(_app_ccdl) + sizeof(_app_impt) + sizeof(_app_expt) + sizeof(_app_rawd);

		tempIMPT.size = (sizeof(_app_impt_entry) * (inApp.import_count + 1));
		for (i = 0; i < inApp.import_count; i++)
		{
			tempIMPT.size += _app_Convert.ToString(inApp.import_data[i].name).Length;
		}
		ushort tempIPad = (16 - (tempIMPT.size & 15)) & 15;
		tempIMPT.size += tempIPad;


		tempEXPT.offset = tempIMPT.offset + tempIMPT.size;
		tempEXPT.size = (sizeof(_app_expt_entry) * (inApp.export_count + 1));
		for (i = 0; i < inApp.export_count; i++)
		{
			tempEXPT.size += _app_Convert.ToString(inApp.export_data[i].name).Length;
		}
		ushort tempEPad = (16 - (tempEXPT.size & 15)) & 15;
		tempEXPT.size += tempEPad;

		tempRAWD.offset = tempEXPT.offset + tempEXPT.size;
		tempRAWD.size = (inApp.bin_size + 15) & 0xFFFFFFF0;
		tempRAWD.origin = 0x80A00000;
		tempRAWD.entry = inApp.bin_entry;
		tempRAWD.prog_size = tempRAWD.size + inApp.bin_bss;

		FILE tempFile = fopen(inPath, "wb");
		if (tempFile == null)
		{
			return false;
		}

		fwrite(tempCCDL, sizeof(_app_ccdl), 1, tempFile);
		fwrite(tempIMPT, sizeof(_app_impt), 1, tempFile);
		fwrite(tempEXPT, sizeof(_app_expt), 1, tempFile);
		fwrite(tempRAWD, sizeof(_app_rawd), 1, tempFile);
		// TODO - Consider extra field.



		// Write Import Table
		_app_impt_entry tempIHeader = new _app_impt_entry(inApp.import_count, {0, 0}, 0);
		fwrite(tempIHeader, sizeof(_app_impt_entry), 1, tempFile);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_impt_entry tempIEntry = _app_impt_entry_default;
		_app_impt_entry tempIEntry = new _app_impt_entry(_app_impt_entry_default);
		for (i = 0; i < inApp.import_count; i++)
		{
			tempIEntry.offset = inApp.import_data[i].offset;
			fwrite(tempIEntry, sizeof(_app_impt_entry), 1, tempFile);
			tempIEntry.str_offset += _app_Convert.ToString(inApp.import_data[i].name).Length;
		}

		// Write Import Strings
		for (i = 0; i < inApp.import_count; i++)
		{
			_fprint_string(inApp.import_data[i].name, tempFile);
		}

		// Write Import Whitespace
		fwrite(tempPadding, 1, tempIPad, tempFile);



		// Write Export Table
		_app_expt_entry tempEHeader = new _app_expt_entry(inApp.export_count, {0, 0}, 0);
		fwrite(tempEHeader, sizeof(_app_expt_entry), 1, tempFile);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: The following line was determined to be a copy constructor call - this should be verified and a copy constructor should be created if it does not yet exist:
//ORIGINAL LINE: _app_expt_entry tempEEntry = _app_expt_entry_default;
		_app_expt_entry tempEEntry = new _app_expt_entry(_app_expt_entry_default);
		for (i = 0; i < inApp.export_count; i++)
		{
			tempEEntry.offset = inApp.export_data[i].offset;
			fwrite(tempEEntry, sizeof(_app_expt_entry), 1, tempFile);
			tempEEntry.str_offset += _app_Convert.ToString(inApp.export_data[i].name).Length;
		}

		// Write Export Strings
		for (i = 0; i < inApp.export_count; i++)
		{
			_fprint_string(inApp.export_data[i].name, tempFile);
		}

		// Write Export Whitespace
		fwrite(tempPadding, 1, tempEPad, tempFile);



		// Write Binary Data
		fwrite(inApp.bin_data, 1, inApp.bin_size, tempFile);
		fwrite(tempPadding, 1, ((16 - (inApp.bin_size & 15)) & 15), tempFile);

		// TODO - Append res data.

		fclose(tempFile);
		return true;
	}

        */


	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

	public static _app_ccdl _app_ccdl = new _app_ccdl();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	//public static _app_ccdl _app_ccdl_default = new _app_ccdl({'C', 'C', 'D', 'L'}, {0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x09, 0x06, 0x24, 0x19, 0x24, 0x42, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
	public static _app_ccdl _app_ccdl_default = new _app_ccdl(new byte[]{(byte)'C', (byte)'C', (byte)'D', (byte)'L' }, new byte[]{0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x09, 0x06, 0x24, 0x19, 0x24, 0x42, 0x00},new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});


	public static _app_impt _app_impt = new _app_impt();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	public static _app_impt _app_impt_default = new _app_impt(new byte[]{ (byte)'I', (byte)'M', (byte)'P', (byte)'T' }, 0x00000008, 0, 0, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});


	public static _app_expt _app_expt = new _app_expt();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	public static _app_expt _app_expt_default = new _app_expt(new byte[] { (byte)'E', (byte)'X', (byte)'P', (byte)'T' }, 0x00000009, 0, 0, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});


	public static _app_rawd _app_rawd = new _app_rawd();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	public static _app_rawd _app_rawd_default = new _app_rawd(new byte[] { (byte)'R', (byte)'A', (byte)'W', (byte)'D' }, 0x00000001, 0, 0, 0x00000000, 0x00000000, 0x80A00000, 0);


	public static _app_impt_entry _app_impt_entry = new _app_impt_entry();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	//public static _app_impt_entry _app_impt_entry_default = new _app_impt_entry(0, {0, 0x00020000}, 0);
	public static _app_impt_entry _app_impt_entry_default = new _app_impt_entry() { };



	public static _app_expt_entry _app_expt_entry = new _app_expt_entry();
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
	//#pragma pack()


	//public static _app_expt_entry _app_expt_entry_default = new _app_expt_entry(0, {0, 0x00020000}, 0);
	public static _app_expt_entry _app_expt_entry_default = new _app_expt_entry();



	public static ushort _app_strlen(string inString)
	{
		int tempLen = inString.Length;
		tempLen += (4 - (tempLen & 3));
		return (ushort)tempLen;
	}



	public static void _fprint_string(void* inString, FILE inStream)
	{
  //      int tempLen = inString.Length;
		//fwrite(inString, 1, tempLen, inStream);
		//ushort i;
		//for (i = 0; i < (4 - (tempLen & 3)); i++)
		//{
		//	fwrite(inString[tempLen], 1, 1, inStream);
		//}
	}

    

    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
    //ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

    public static uc_err bridge_init(uc_engine uc, app _app)
	{
		hooks_init(uc, _app);

		return UC_ERR_OK;
	}



	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_VERSION 2,9,1,0
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_LEVEL PTW32_LEVEL_MAX
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EDEADLK EDEADLOCK
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define HANDLE void *
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define DWORD unsigned long
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SEM_VALUE_MAX INT_MAX
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_DLLPORT __declspec (dllexport)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_DLLPORT __declspec (dllimport)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_CDECL __cdecl
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_CANCELED ((void *)(size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0}
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -2)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t)(size_t) -3)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_COND_INITIALIZER ((pthread_cond_t)(size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t)(size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t)(size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_push( _rout, _arg ) { ptw32_cleanup_t _cleanup; _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); _cleanup.arg = (_arg); __try {
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_pop( _execute ) } __finally { if( _execute || AbnormalTermination()) { (*(_cleanup.routine))( _cleanup.arg ); } } }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_push( _rout, _arg ) { ptw32_cleanup_t _cleanup; ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) );
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_pop( _execute ) (void) ptw32_pop_cleanup( _execute ); }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_push( _rout, _arg ) { PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), (void *) (_arg) );
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define pthread_cleanup_pop( _execute ) cleanup.execute( _execute ); }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define errno (*_errno())
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define _ftime ftime
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define _timeb timeb
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define __except( E ) __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PtW32CatchAll catch( ptw32_exception & ) { throw; } catch( ... )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define catch( E ) catch( ptw32_exception & ) { throw; } catch( E )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_DLLPORT __declspec (dllexport)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PTW32_DLLPORT __declspec (dllimport)
	//#include <minwindef.h>
	//#include <minwinbase.h>
	//#include <sysinfoapi.h>
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define DECLSPEC __declspec(dllexport)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define DECLSPEC __declspec(dllexport)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDLCALL __cdecl
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDLCALL _System
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INLINE __inline__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INLINE __inline
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define __inline__ __inline
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INLINE inline
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define __inline__ inline
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FORCE_INLINE __forceinline
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FORCE_INLINE static __inline__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FORCE_INLINE static SDL_INLINE
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_NORETURN __declspec(noreturn)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define NULL ((void *)0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FALLTHROUGH [[fallthrough]]
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAS_FALLTHROUGH __has_attribute(__fallthrough__)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FALLTHROUGH do {} while (0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define alloca __builtin_alloca
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define alloca _alloca
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SIZE_MAX SIZE_MAX
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SIZE_MAX ((size_t) -1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define _SDL_HAS_BUILTIN(x) __has_builtin(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define _SDL_HAS_BUILTIN(x) 0
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TABLESIZE(table) SDL_arraysize(table)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_STRINGIFY_ARG(arg) #arg
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_static_cast(type, expression) static_cast<type>(expression)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_const_cast(type, expression) const_cast<type>(expression)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_reinterpret_cast(type, expression) ((type)(expression))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_static_cast(type, expression) ((type)(expression))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_const_cast(type, expression) ((type)(expression))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FOURCC(A, B, C, D) ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_SINT8 ((Sint8)0x7F)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_SINT8 ((Sint8)(~0x7F))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_UINT8 ((Uint8)0xFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_UINT8 ((Uint8)0x00)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_SINT16 ((Sint16)0x7FFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_UINT16 ((Uint16)0xFFFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_UINT16 ((Uint16)0x0000)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_UINT32 ((Uint32)0x00000000)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLT_EPSILON FLT_EPSILON
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLT_EPSILON 1.1920928955078125e-07F
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIs64 PRIs64
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIu64 PRIu64
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIx64 PRIx64
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIX64 PRIX64
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIs32 PRId32
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIu32 PRIu32
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIx32 PRIx32
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRIX32 PRIX32
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_IN_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INOUT_Z_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_CAP(x) _Out_cap_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_IN_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INOUT_Z_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_CAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OUT_Z_BYTECAP(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_COMPILE_TIME_ASSERT(name, x) typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_stack_free(data)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_stack_free(data) SDL_free(data)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_copyp(dst, src) { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } SDL_memcpy((dst), (src), sizeof (*(src)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ICONV_ERROR (size_t)-1
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ICONV_E2BIG (size_t)-2
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ICONV_EILSEQ (size_t)-3
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ICONV_EINVAL (size_t)-4
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_malloc malloc
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_calloc calloc
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_realloc realloc
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_free free
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_memset memset
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_memcpy memcpy
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_memmove memmove
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_memcmp memcmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strlcpy strlcpy
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strlcat strlcat
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strlen strlen
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcslen wcslen
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcslcpy wcslcpy
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcslcat wcslcat
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strdup strdup
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcsdup wcsdup
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strchr strchr
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strrchr strrchr
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strstr strstr
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcsstr wcsstr
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strtokr strtok_r
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strcmp strcmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcscmp wcscmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strncmp strncmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_wcsncmp wcsncmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strcasecmp strcasecmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_strncasecmp strncasecmp
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_sscanf sscanf
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_vsscanf vsscanf
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_snprintf snprintf
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_vsnprintf vsnprintf
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_size_mul_overflow(a, b, ret) (_SDL_size_mul_overflow_builtin(a, b, ret))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_size_add_overflow(a, b, ret) (_SDL_size_add_overflow_builtin(a, b, ret))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDLMAIN_DECLSPEC DECLSPEC
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PS2_SKIP_IOP_RESET() void reset_IOP(); void reset_IOP() {}
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define main SDL_main
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() __debugbreak()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() __builtin_debugtrap()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "bkpt #22\n\t" )
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint() raise(SIGTRAP)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TriggerBreakpoint()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FUNCTION __func__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FUNCTION __FUNCTION__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FILE __FILE__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_LINE __LINE__
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_disabled_assert(condition) do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_enabled_assert(condition) do { while ( !(condition) ) { static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); if (sdl_assert_state == SDL_ASSERTION_RETRY) { continue; } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { SDL_TriggerBreakpoint(); } break; } } while (SDL_NULL_WHILE_LOOP_CONDITION)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_release(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_release(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_release(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_release(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_always(condition) SDL_enabled_assert(condition)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_state SDL_AssertState
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_assert_data SDL_AssertData
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CompilerBarrier() _ReadWriteBarrier()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CompilerBarrier() { SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() __machine_rel_barrier()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction() __asm__ __volatile__("pause\n")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction() __asm__ __volatile__("yield" ::: "memory")
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction() __asm__ __volatile__("or 27,27,27");
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction() _mm_pause()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction() __yield()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CPUPauseInstruction()
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER __BYTE_ORDER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER BYTE_ORDER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER BYTE_ORDER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER SDL_LIL_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER SDL_BIG_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER SDL_BIG_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTEORDER SDL_LIL_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLOATWORDORDER SDL_LIL_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLOATWORDORDER SDL_BIG_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLOATWORDORDER SDL_LIL_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLOATWORDORDER SDL_BIG_ENDIAN
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_FLOATWORDORDER SDL_BYTEORDER
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define HAS_BUILTIN_BSWAP16 (_SDL_HAS_BUILTIN(__builtin_bswap16)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define HAS_BUILTIN_BSWAP32 (_SDL_HAS_BUILTIN(__builtin_bswap32)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define HAS_BUILTIN_BSWAP64 (_SDL_HAS_BUILTIN(__builtin_bswap64)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define HAS_BROKEN_BSWAP (__GNUC__ == 2 && __GNUC_MINOR__ <= 95)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap16(x) __builtin_bswap16(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap16(x) _byteswap_ushort(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap32(x) __builtin_bswap32(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap32(x) _byteswap_ulong(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap64(x) __builtin_bswap64(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Swap64(x) _byteswap_uint64(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE16(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE32(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE64(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapFloatLE(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE16(X) SDL_Swap16(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE32(X) SDL_Swap32(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE64(X) SDL_Swap64(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE16(X) SDL_Swap16(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE32(X) SDL_Swap32(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapLE64(X) SDL_Swap64(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE16(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE32(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapBE64(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SwapFloatBE(X) (X)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_THREAD_ANNOTATION_ATTRIBUTE__(x)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CAPABILITY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCOPED_CAPABILITY SDL_THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_GUARDED_BY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PT_GUARDED_BY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ACQUIRED_BEFORE(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ACQUIRED_AFTER(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_REQUIRES(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_REQUIRES_SHARED(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ACQUIRE(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ACQUIRE_SHARED(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_RELEASE(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_RELEASE_SHARED(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_RELEASE_GENERIC(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(release_generic_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TRY_ACQUIRE(x, y) SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(x, y))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TRY_ACQUIRE_SHARED(x, y) SDL_THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(x, y))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_EXCLUDES(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ASSERT_CAPABILITY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ASSERT_SHARED_CAPABILITY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_RETURN_CAPABILITY(x) SDL_THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_NO_THREAD_SAFETY_ANALYSIS SDL_THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MUTEX_MAXWAIT (~(Uint32)0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_mutexP(m) SDL_LockMutex(m)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_mutexV(m) SDL_UnlockMutex(m)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_beginthread _beginthreadex
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_endthread _endthreadex
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_beginthread _beginthread
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_endthread _endthread
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize_REAL(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_CreateThreadWithStackSize(fn, name, stacksize, data) SDL_CreateThreadWithStackSize(fn, name, stacksize, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_MASK_BITSIZE (0xFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_MASK_DATATYPE (1<<8)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_MASK_ENDIAN (1<<12)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_MASK_SIGNED (1<<15)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_U16 AUDIO_U16LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S16 AUDIO_S16LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S32 AUDIO_S32LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_F32 AUDIO_F32LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_U16SYS AUDIO_U16LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S16SYS AUDIO_S16LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S32SYS AUDIO_S32LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_F32SYS AUDIO_F32LSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_U16SYS AUDIO_U16MSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S16SYS AUDIO_S16MSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_S32SYS AUDIO_S32MSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define AUDIO_F32SYS AUDIO_F32MSB
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE|SDL_AUDIO_ALLOW_SAMPLES_CHANGE)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_LoadWAV(file, spec, audio_buf, audio_len) SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | ((bits) << 8) | ((bytes) << 0))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BYTESPERPIXEL(X) (SDL_ISPIXELFORMAT_FOURCC(X) ? ((((X) == SDL_PIXELFORMAT_YUY2) || ((X) == SDL_PIXELFORMAT_UYVY) || ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ISPIXELFORMAT_INDEXED(format) (!SDL_ISPIXELFORMAT_FOURCC(format) && ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ISPIXELFORMAT_PACKED(format) (!SDL_ISPIXELFORMAT_FOURCC(format) && ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ISPIXELFORMAT_ARRAY(format) (!SDL_ISPIXELFORMAT_FOURCC(format) && ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ISPIXELFORMAT_ALPHA(format) ((SDL_ISPIXELFORMAT_PACKED(format) && ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || (SDL_ISPIXELFORMAT_ARRAY(format) && ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_ISPIXELFORMAT_FOURCC(format) ((format) && (SDL_PIXELFLAG(format) != 1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_Colour SDL_Color
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SaveBMP(surface, file) SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BlitSurface SDL_UpperBlit
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BlitScaled SDL_UpperBlitScaled
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_ISUNDEFINED(X) (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_WINDOWPOS_ISCENTERED(X) (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDLK_SCANCODE_MASK (1<<30)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON(X) (1 << ((X)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_QuitRequested() (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TOUCH_MOUSEID ((Uint32)-1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_MOUSE_TOUCHID ((Sint64)-1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_CONSTANT (1u<<0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_SINE (1u<<1)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_TRIANGLE (1u<<3)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_RAMP (1u<<6)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_SPRING (1u<<7)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_DAMPER (1u<<8)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_INERTIA (1u<<9)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_FRICTION (1u<<10)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_CUSTOM (1u<<11)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_GAIN (1u<<12)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_AUTOCENTER (1u<<13)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_STATUS (1u<<14)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_HAPTIC_PAUSE (1u<<15)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_SHAPEMODEALPHA(mode) (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_VERSION(x) { (x)->major = SDL_MAJOR_VERSION; (x)->minor = SDL_MINOR_VERSION; (x)->patch = SDL_PATCHLEVEL; }
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_VERSIONNUM(X, Y, Z) ((X)*1000 + (Y)*100 + (Z))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_COMPILEDVERSION SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_VERSION_ATLEAST(X, Y, Z) ((SDL_MAJOR_VERSION >= X) && (SDL_MAJOR_VERSION > X || SDL_MINOR_VERSION >= Y) && (SDL_MAJOR_VERSION > X || SDL_MINOR_VERSION > Y || SDL_PATCHLEVEL >= Z))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define SDL_INIT_EVERYTHING ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR )

	//void* malloc(size_t len);
	internal static void br_malloc(uc_engine uc)
	{
		uint len;
		//dumpREG(uc);
		uc_reg_read(uc, UC_MIPS_REG_A0, out len);
		uint p = vm_malloc(len);
		if (len == 0)
		{
			Console.Write("vm_malloc 0\n");
		}
		if (p == 0 && len != 0)
		{
			dumpREG(uc);
			dumpStackCall(uc, 0xa0000000);
			dumpAsm(uc);
			Debug.Assert(0);
		}
		uc_reg_write(uc, UC_MIPS_REG_V0, p);

		uint ra;
		uc_reg_read(uc, UC_MIPS_REG_RA, out ra);
		uc_reg_write(uc, UC_MIPS_REG_PC, ra);
	}
	//void free(void*);
	internal static void br_free(uc_engine uc)
	{
		uint addr;
		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_A0, out addr);
		vm_free(addr);
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
	//void* realloc(void*, size_t);
	internal static void br_realloc(uc_engine uc)
	{
		uint addr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out addr);

		uint size;
		uc_reg_read(uc, UC_MIPS_REG_A1, out size);

		uint p = vm_realloc(addr, size);
		uc_reg_write(uc, UC_MIPS_REG_V0, p);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//void __func(void);
	internal static void br_common(uc_engine uc)
	{
		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//public static fixed byte __to_locale_ansi_string[256];

	//public static string __to_locale_ansi(ref char inInput)
	//{
	//	ushort i;
	//	string tempString = (string)inInput;
	//	for (i = 0; (i < 255) && (tempString[i] != '\0'); i += 2)
	//	{
	//		__to_locale_ansi_string = StringFunctions.ChangeCharacter(__to_locale_ansi_string, i, tempString[i]);
	//	}
	//	tempString = StringFunctions.ChangeCharacter(tempString, i, '\0');
	//	return tempString;
	//}

	internal static void br__to_locale_ansi(uc_engine uc)
	{
		uint inInputpPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out inInputpPtr);

		uc_err err = new uc_err();
		//err = uc_mem_read(uc, inInputpPtr, __to_locale_ansi_string, sizeof(sbyte));
		//if (err != null)
		//{
		//	Console.Write("Failed on uc_mem_read() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
		//	return;
		//}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: sbyte * out = __to_locale_ansi((char*)__to_locale_ansi_string);
		//sbyte @out = __to_locale_ansi(ref (char)__to_locale_ansi_string);

		uint ret = inInputpPtr;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}


	internal static ulong s_tempTicks = 0;
	// time ms
	public static uint OSTimeGet()
	{
		if (s_tempTicks == 0)
		{
			s_tempTicks = SDL_GetTicks64();
		}

		//���tick��λ��10ms  Ҳ���� =  1000 / OS_TICKS_PER_SEC
		//����tempTicks��λ��1ms 
		ulong tempTicks = SDL_GetTicks64() - s_tempTicks;
		//printf("%lld\n", tempTicks);
		//static uint64_t ticks = 0;
		//printf("%lld\n", tempTicks - ticks);
		//ticks = tempTicks;


		tempTicks *= DefineConstants.OS_TICKS_PER_SEC;
		tempTicks /= 1000;

		return (uint)tempTicks;
	}

   

    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
    private static ulong br_GetTickCount_res = 0;


	internal static void br_GetTickCount(uc_engine uc)
	{
		FILETIME ft = new FILETIME();
		ulong tmpres = 0;
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//	static ulong res = 0;

		GetSystemTimeAsFileTime(ft);

		tmpres |= ft.dwHighDateTime;
		tmpres <<= 32;
		tmpres |= ft.dwLowDateTime;

		if (br_GetTickCount_res == 0)
		{
			br_GetTickCount_res = tmpres;
			tmpres = 0;
		}
		else
		{
			tmpres = tmpres - br_GetTickCount_res;
		}

		uint ret = (uint)(tmpres & 0xFFFFFFFF);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA,out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



    internal static void br_OSTimeGet(uc_engine uc)
	{
		uint tick_time_10ms = OSTimeGet();

		uint ret = tick_time_10ms;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



	internal static void br__kbd_get_status(uc_engine uc)
	{
		uint ksPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out ksPtr);

		KEY_STATUS* ks = (KEY_STATUS*)toHostPtr(ksPtr);
		_kbd_get_status(ks);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line could not be converted:
    //public static sem_t[] s_semaphore_map = {((object*)0), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null};
    public static sem_t[] s_semaphore_map = new sem_t[128];
    //typedef void OS_EVENT;
    //OS_EVENT* OSSemCreate(uint16_t cnt);
    internal static void br_OSSemCreate(uc_engine uc)
	{
		uint index = 1;
		uint cnt;
		uc_reg_read(uc, UC_MIPS_REG_A0, out cnt);


		sem_t* sem = (sem_t*)malloc(sizeof(sem_t));
		int sem_ret = (int)sem_init(sem, 0, cnt);
		if (sem_ret != 0)
		{
			Console.Write("Failed sem_init with error : {0:D} \n", (_errno()));
			Debug.Assert(0);
		}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: for (; index < sizeof(s_semaphore_map) / sizeof(s_semaphore_map[0]); ++index)
		for (; index < s_semaphore_map.Length; ++index)
		{
			if (s_semaphore_map[index].id==0)
			{
				break;
			}
		}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: if (index >= sizeof(s_semaphore_map) / sizeof(s_semaphore_map[0]))
		if (index >= s_semaphore_map.Length)
		{
			Console.Write("Failed sem_init with error : {0:D}, index {1:D} \n", (_errno()), index);
			Debug.Assert(0);
		}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: s_semaphore_map[index] = sem;
		s_semaphore_map[index] = *sem;

		uint ret = index;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA,out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

    

    private static int sem_init(sem_t* sem, int v, uint cnt)
    {
        sem->id = cnt;
        return v;
    }

    /*
	extern OS_EVENT* OSSemDel(OS_EVENT *event, uint8_t option, uint8_t* error);
	extern void      OSSemPend(OS_EVENT* event, uint16_t timeout, uint8_t* error);
	extern uint8_t   OSSemPost(OS_EVENT* event);
	*/

    internal static void br_OSSemPend(uc_engine uc)
	{
		uint eventVal;
		uint timeout;
		uint errorPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out eventVal);
		uc_reg_read(uc, UC_MIPS_REG_A1, out timeout);
		uc_reg_read(uc, UC_MIPS_REG_A2, out errorPtr);

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line could not be converted:
		sem_t sem = s_semaphore_map[eventVal];

		uint ret = sem_wait(sem);
	#if _WIN32
		uint tid = GetCurrentThreadId();
	#else
		uint tid = pthread_self();
	#endif
		//printf("tid: %x, sem_wait(%lx) index %d, ret %d \n", tid, (size_t)sem, eventVal, ret);


		*(uint*)toHostPtr(errorPtr) = DefineConstants.OS_NO_ERR;

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



    internal static void br_OSSemPost(uc_engine uc)
	{
		uint eventVal;
		uc_reg_read(uc, UC_MIPS_REG_A0, out eventVal);

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line could not be converted:
		sem_t sem = s_semaphore_map[eventVal];

		uint ret = sem_post(sem);

	#if _WIN32
		uint tid = GetCurrentThreadId();
	#else
		uint tid = pthread_self();
	#endif
		//printf("tid: %x, sem_post(%lx) index %d, ret %d \n", tid, (size_t)sem, eventVal, ret);

		uint retVal = DefineConstants.OS_NO_ERR;
		uc_reg_write(uc, UC_MIPS_REG_V0, retVal);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

   

    //uint8_t   OSTaskCreate(void (*task)(void* data), void* data, OS_STK* stack, uint8_t priority);
    internal static void br_OSTaskCreate(uc_engine uc)
	{
		/*
		dumpREG(uc);
		dumpStackCall(uc);
		dumpAsm(uc);
		exit(0);
		*/

		//�����̣߳����߳������uc_emu_start

		uc_err err = new uc_err();
		uint taskFuncAddr;
		uint dataPtr;
		uint stackPtr;
		uint priority;
		uc_reg_read(uc, UC_MIPS_REG_A0,out taskFuncAddr);
		uc_reg_read(uc, UC_MIPS_REG_A1, out dataPtr);
		uc_reg_read(uc, UC_MIPS_REG_A2, out stackPtr);
		uc_reg_read(uc, UC_MIPS_REG_A3, out priority);

		Console.Write("br_OSTaskCreate(0x{0:x}, 0x{1:x}, 0x{2:x}, 0x{3:x})\n", taskFuncAddr, dataPtr, stackPtr, priority);

		uint ret = OSTaskCreate(taskFuncAddr, dataPtr, stackPtr, priority);

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//extern void* waveout_open(waveout_args* args);
	internal static void br_waveout_open(uc_engine uc)
	{
		uint argsPtr;
		uint ret = 0;
		uc_reg_read(uc, UC_MIPS_REG_A0, out argsPtr);

		waveout_args* args = (waveout_args*)toHostPtr(argsPtr);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		waveout_args* argsCpy = (waveout_args*)malloc(sizeof(waveout_args));
		if (args != null && argsCpy != null)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memcpy' has no equivalent in C#:
			memcpy(argsCpy, args, sizeof(waveout_args));
			ret = waveout_open(argsCpy);
		}

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//extern int waveout_write(waveout_inst* inst, char* buffer, int count);
	internal static void br_waveout_write(uc_engine uc)
	{
		uint instPtr;
		uint bufferPtr;
		uint count;
		uc_reg_read(uc, UC_MIPS_REG_A0, out instPtr);
		uc_reg_read(uc, UC_MIPS_REG_A1, out bufferPtr);
		uc_reg_read(uc, UC_MIPS_REG_A2, out count);

		//dumpMem(toHostPtr(bufferPtr), count);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: sbyte* buff = (sbyte*)malloc(count);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		byte* buff = (byte*)malloc(count);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memcpy' has no equivalent in C#:
		memcpy(buff, toHostPtr(bufferPtr), count);
		uint ret = waveout_write(instPtr,  buff, count);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//typedef void waveout_inst;
	//int waveout_close(waveout_inst*);
	internal static void br_waveout_close(uc_engine uc)
	{
		uint ptr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out ptr);

		uint ret = 0;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//int waveout_can_write();
	internal static void br_waveout_can_write(uc_engine uc)
	{
		uint ret = waveout_can_write();
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	internal static void br_waveout_set_volume(uc_engine uc)
	{
		uint vol;
		uc_reg_read(uc, UC_MIPS_REG_A0, out vol);

		uint ret = waveout_set_volume(vol);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



	//void* _lcd_get_frame()
	internal static void br__lcd_get_frame(uc_engine uc)
	{
		uint ptr = _lcd_get_frame();
		uc_reg_write(uc, UC_MIPS_REG_V0, ptr);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
	//void* lcd_get_frame()
	internal static void br_lcd_get_frame(uc_engine uc)
	{
		br__lcd_get_frame(uc);
	}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//void updateFb();

	//void _lcd_set_frame()
	internal static void br__lcd_set_frame(uc_engine uc)
	{
		//update fb
		updateFb();

		br_common(uc);
	}

	internal static void br_lcd_set_frame(uc_engine uc)
	{
		br__lcd_set_frame(uc);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int br_fread_debug_fread = 0;



	//int fread(void* ptr, size_t size, size_t count, FILE* stream);
	internal static void br_fread(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint ptr;
		uint size;
		uint count;
		uint stream;
		uint read_size;
		int read_ret = -1;
		uc_reg_read(uc, UC_MIPS_REG_A0,out ptr);
		uc_reg_read(uc, UC_MIPS_REG_A1, out size);
		uc_reg_read(uc, UC_MIPS_REG_A2, out count);
		uc_reg_read(uc, UC_MIPS_REG_A3, out stream);

		read_size = size * count;

		_file_t* _filep = (_file_t*)toHostPtr(stream);
		_file_t _file = *_filep;
        if (_filep == null)
		{
			read_ret = -1;
		}
		else
		{
			if (_file.type == (int)_file_type_e._file_type_mem)
			{
				_file_mem_t* _file_memp = (_file_mem_t*)toHostPtr(_file.data);
                _file_mem_t _file_mem = *_file_memp;
                if (_file_memp == null)
				{
					read_ret = -1;
				}
				else if (_file_mem.read!=0)
				{
					void* buff = toHostPtr(_file_mem.@base + _file_mem.offset);
					void* distPtr = toHostPtr(ptr);
					if (buff == null || distPtr == null)
					{
						read_ret = -1;
					}
					else
					{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memcpy' has no equivalent in C#:
						memcpy(distPtr, buff, read_size);
						read_ret = (int)read_size;

						if (read_size > 0)
						{
							_file_mem.offset += read_size;
						}
					}
				}
			}
			else if (_file.type == (int)_file_type_e._file_type_file)
			{
				void* buff = toHostPtr(ptr);
				if (buff != null)
				{
					read_ret = (int)vm_fread(buff, size, count, _file.data);
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//				static int debug_fread = 0;
					if (br_fread_debug_fread != 0)
					{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: sbyte* out = (sbyte *)malloc(read_size *3 + 1);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
						sbyte* @out = (sbyte *)malloc(read_size * 3 + 1);
						if (@out != null)
						{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
							memset(@out, 0x00, read_size);
							toHexString(buff, read_size, @out);
							//Console.Write("vm_fread(buff = {0}, size = {1:D}, count = {2:D}, stream = {3:D}) = {4:D}\n", @out, size, count, _file.data, read_ret);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
							free(@out);
						}
					}
				}
				else
				{
					read_ret = -1;
				}
			}
			else
			{
				Console.Write("Failed br_fread with: {0:D}\n", _file.type);
				Debug.Assert(0);
			}
		}

		uint ret =(uint) read_ret;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA,out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//int sprintf(char* buff, const char* fmt, char * va_list);
	public static uint vm_sprintf(uc_engine uc, uint buffPtr, uint fmtPtr, uint val1Ptr, uint val2Ptr)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
 sbyte* buff = (sbyte*)toHostPtr(buffPtr);
		//sbyte buff = (string)toHostPtr(buffPtr);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
 sbyte* fmt = (sbyte*)toHostPtr(fmtPtr);
		//sbyte fmt = (string)toHostPtr(fmtPtr);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
 sbyte* val1 = (sbyte *)toHostPtr(val1Ptr);
		//sbyte val1 = (string)toHostPtr(val1Ptr);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
/*//ORIGINAL LINE:*/ sbyte* val2 = (sbyte*)toHostPtr(val2Ptr);
		//sbyte val2 = (string)toHostPtr(val2Ptr);

		if ((null) == val1 && (null) != val2)
		{
			return sprintf(buff, fmt, val1Ptr, val2);
		}
		else if ((null) == val1 && (null) == val2)
		{
			return sprintf(buff, fmt, val1Ptr, val2Ptr);
		}

		return sprintf(buff, fmt, val1, val2);
	}

    private static uint sprintf(sbyte* buff, sbyte* fmt, uint val1Ptr, sbyte* val2)
    {
        throw new NotImplementedException();
    }

    internal static void br_sprintf(uc_engine uc)
	{
		/*
		uc_err err;
		uint32_t buffPtr;
		uint32_t fmtPtr;
		uint32_t var1Ptr;
		uint32_t var2Ptr;
		uint32_t sp;
	
		uc_reg_read(uc, UC_MIPS_REG_A0, &buffPtr);
		uc_reg_read(uc, UC_MIPS_REG_A1, &fmtPtr);
		uc_reg_read(uc, UC_MIPS_REG_A2, &var1Ptr);
		uc_reg_read(uc, UC_MIPS_REG_A3, &var2Ptr);
		uc_reg_read(uc, UC_MIPS_REG_SP, &sp);
	
	
		//ģ�������
		char va_list_buff[128];
		char* buff = (char*)toHostPtr(buffPtr);
		char* fmt = (char*)toHostPtr(fmtPtr);
		char* var1 = (char*)toHostPtr(var1Ptr);
		char* var2 = (char*)toHostPtr(var2Ptr);
		dumpMem(toHostPtr(sp-128), 128);
		*/

		my_sprintf(uc);

		/*
		uint32_t ret = 0;
		uc_reg_write(uc, UC_MIPS_REG_V0, &ret);
	
		uint32_t pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, &pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, &pc);
		*/
	}

	//typedef void FSYS_FILE;
	//extern FSYS_FILE* fsys_fopen(const char* name, const char* mode);
	internal static void br_fsys_fopen(uc_engine uc)
	{
		uint namePtr;
		uint modePtr;
		uc_reg_read(uc, UC_MIPS_REG_A0,out namePtr);
		uc_reg_read(uc, UC_MIPS_REG_A1,out modePtr);

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
        sbyte* name = (sbyte*)toHostPtr(namePtr);
	
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
        byte* mode = (byte*)toHostPtr(modePtr);
		
		uint fpPtr = fsys_fopen(toString(name), toString(mode));
		Console.Write("fsys_fopen(\"{0}\", \"{1}\") = {2:D}\n",toString( name), *mode, fpPtr);
		uint ret = fpPtr;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);
		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}


	//typedef void FSYS_FILE;
	//extern int fsys_fclose(FSYS_FILE*);
	internal static void br_fsys_fclose(uc_engine uc)
	{
		uint file;
		uc_reg_read(uc, UC_MIPS_REG_A0, out file);

		uint ret = fsys_fclose(file);

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);
		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
	//int fsys_fseek(FSYS_FILE*, int offset, int origin);
	internal static void br_fsys_fseek(uc_engine uc)
	{
		uint file;
		uint offset;
		uint origin;
		uc_reg_read(uc, UC_MIPS_REG_A0, out file);
		uc_reg_read(uc, UC_MIPS_REG_A1, out offset);
		uc_reg_read(uc, UC_MIPS_REG_A2, out origin);

		uint ret = fsys_fseek(file, offset, origin);

		//printf("fsys_fseek(%08x, %d,  %d,) = %d\n", file, offset, origin, ret);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	internal static void br_fsys_ftell(uc_engine uc)
	{
		uint file;
		uc_reg_read(uc, UC_MIPS_REG_A0, out file);

		uint ret = fsys_ftell(file);

		//printf("fsys_ftell(%d) = %08x\n", file,ret);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int br_fsys_fwrite_debug_fwrite = 1;

	//uint32_t fsys_fwrite(void* ptr, uint32_t size, uint32_t count, uint32_t stream)
	internal static void br_fsys_fwrite(uc_engine uc)
	{
		uc_err err = new uc_err();
		int ret =  - 1;
		uint ptr;
		uint size;
		uint count;
		uint stream;
		uc_reg_read(uc, UC_MIPS_REG_A0, out ptr);
		uc_reg_read(uc, UC_MIPS_REG_A1, out size);
		uc_reg_read(uc, UC_MIPS_REG_A2, out count);
		uc_reg_read(uc, UC_MIPS_REG_A3, out stream);

		void* buff = toHostPtr(ptr);
		if (buff != null)
		{
			ret = (int)fsys_fwrite(buff, size, count, stream);
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//		static int debug_fwrite = 1;
			if (br_fsys_fwrite_debug_fwrite==0)
			{
				uint read_size = size * count;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
                sbyte* @out = (sbyte*)malloc((uint)(read_size * 3 + 1));
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
				//sbyte @out = (string)malloc((uint)(read_size * 3 + 1));
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
				memset(@out, 0x00, read_size);
				toHexString(buff, read_size,  @out);
				//Console.Write("fsys_fwrite(buff = {0}, size = {1:D}, count = {2:D}, stream = {3:D}) = {4:D}\n", @out, size, count, stream, ret);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
				free(@out);
			}
		}

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA,out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int br_fsys_fread_debug_fread = 0;

	//uint32_t fsys_fread(void* ptr, uint32_t size, uint32_t count, uint32_t stream)
	internal static void br_fsys_fread(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint read_ret = -1;
		uint ptr;
		uint size;
		uint count;
		uint stream;
		uc_reg_read(uc, UC_MIPS_REG_A0, out ptr);
		uc_reg_read(uc, UC_MIPS_REG_A1, out size);
		uc_reg_read(uc, UC_MIPS_REG_A2, out count);
		uc_reg_read(uc, UC_MIPS_REG_A3, out stream);

		object buff = toHostPtr(ptr);
		if (buff != null)
		{
			read_ret = vm_fread(buff, size, count, stream);
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//		static int debug_fread = 0;
			if (br_fsys_fread_debug_fread)
			{
				uint read_size = size * count;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: sbyte* out = (sbyte*)malloc(read_size * 3 + 1);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
				sbyte @out = (string)malloc(read_size * 3 + 1);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
				memset(@out, 0x00, read_size);
				toHexString(buff, read_size, ref @out);
				Console.Write("vm_fread(buff = {0}, size = {1:D}, count = {2:D}, stream = {3:D}) = {4:D}\n", @out, size, count, stream, read_ret);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
				free(@out);
			}
		}
		else
		{
			read_ret = -1;
		}

		uc_reg_write(uc, UC_MIPS_REG_V0, read_ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, out pc);
	}

	internal static void br_fsys_feof(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint file;
		uc_reg_read(uc, UC_MIPS_REG_A0, file);

		uint ret = fsys_feof(file);

		Console.Write("fsys_feof({0:D}) = {1:x8}\n", file, ret);
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



	//extern int _sys_judge_event(void* in);
	internal static void br__sys_judge_event(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint inPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out inPtr);

		//void* in = toHostPtr(inPtr);

		// 0 ������ С�� 0 �˳�ѭ��
		uint ret = 0;

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}


	// extern void OSTimeDly(uint16_t ticks);
	internal static void br_OSTimeDly(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint ticks;
		uc_reg_read(uc, UC_MIPS_REG_A0, out ticks);

		//tick ��λ��10ms Ҳ���� =  1000 / OS_TICKS_PER_SE
		ticks *= 1000;
		ticks /= DefineConstants.OS_TICKS_PER_SEC;
		SDL_Delay(ticks);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, out pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, out pc);
	}

	//extern void *memset(void *outDest, int inValue, size_t inLength);
	internal static void br_memset(uc_engine uc)
	{
		uint ret = 0;
		uc_err err = new uc_err();
		uint outDestPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, out outDestPtr);
		uint inValue;
		uc_reg_read(uc, UC_MIPS_REG_A1, out inValue);
		uint inLength;
		uc_reg_read(uc, UC_MIPS_REG_A2, out inLength);

		void* inn = toHostPtr(outDestPtr);
		if (inn != null)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
			object @out = memset(inn, inValue, inLength);
			ret = toVmPtr(@out);
		}
		else
		{
			ret = 0;
		}

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	//extern void* memcpy(void* outDest, const void* inSrc, size_t inLength);
	internal static void br_memcpy(uc_engine uc)
	{
		uint ret = 0;
		uc_err err = new uc_err();
		uint outDestPtr;
		uc_reg_read(uc, UC_MIPS_REG_A0, outDestPtr);
		uint inSrcPtr;
		uc_reg_read(uc, UC_MIPS_REG_A1, inSrcPtr);
		uint inLength;
		uc_reg_read(uc, UC_MIPS_REG_A2, inLength);

		object outDest = toHostPtr(outDestPtr);
		object inSrc = toHostPtr(inSrcPtr);
		if (outDest != null && inSrc != null)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memcpy' has no equivalent in C#:
			object @out = memcpy(outDest, inSrc, inLength);
			ret = toVmPtr(@out);
		}
		else
		{
			ret = 0;
		}

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int br_fseek_debug_fseek = 0;



	//extern int fseek(FILE* stream, long int offset, int origin);
	internal static void br_fseek(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint origin;
		uint offset;
		uint stream;
		uint read_ret = -1;
		uc_reg_read(uc, UC_MIPS_REG_A2, origin);
		uc_reg_read(uc, UC_MIPS_REG_A1, offset);
		uc_reg_read(uc, UC_MIPS_REG_A0, stream);

		_file_t _file = (_file_t)toHostPtr(stream);
		if (_file != null)
		{
			if (_file.type == (int)_file_type_e._file_type_mem)
			{
				_file_mem_t _file_mem = (_file_mem_t)toHostPtr(stream);
				if (_file == null)
				{
					read_ret = -1;
				}
			}
			else if (_file.type == (int)_file_type_e._file_type_file)
			{
				read_ret = fsys_fseek(_file.data, offset, origin);
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//			static int debug_fseek = 0;
				if (br_fseek_debug_fseek)
				{
					Console.Write("fsys_fseek(stream = {0:D}, offset = {1:D} , origin = {2:D}) = {3:D}\n", _file.type, offset, origin, read_ret);
				}
			}
			else
			{
				Console.Write("Failed br_fseek with: {0:D}\n", _file.type);
				Debug.Assert(0);
			}
		}

		uint ret = read_ret;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	internal static void br_get_current_language(uc_engine uc)
	{
		uint val0;
		uint val1;
		uint val2;
		uint val3;
		uc_reg_read(uc, UC_MIPS_REG_A0, val0);
		uc_reg_read(uc, UC_MIPS_REG_A1, val1);
		uc_reg_read(uc, UC_MIPS_REG_A2, val2);
		uc_reg_read(uc, UC_MIPS_REG_A3, val3);

		//char* _val0 = (char*)toHostPtr(val0);
		//char* _val1 = (char*)toHostPtr(val1);

		uint ret = 0;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}


	internal static void br_fsys_fopenW(uc_engine uc)
	{
		uc_err err = new uc_err();
		uint namePtr;
		uint modePtr;
		uc_reg_read(uc, UC_MIPS_REG_A0,out namePtr);
		uc_reg_read(uc, UC_MIPS_REG_A1,out modePtr);

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
        sbyte* name = (sbyte*)toHostPtr(namePtr);

        //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
        sbyte* mode = (sbyte*)toHostPtr(modePtr);


		string namestr = WString2String(toString(name));
		string modestr = WString2String(toString(mode));

		uint fpPtr = fsys_fopen(namestr, modestr);
		Console.Write("fsys_fopenW(\"{0}\", \"{1}\") = {2:D}\n", namestr, modestr, fpPtr);
		uint ret = fpPtr;
		uc_reg_write(uc, UC_MIPS_REG_V0, ret);
		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}



	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define br_none NULL

	public delegate void br_func(uc_engine uc);
	public static _hook_code_func_[] _hook_code_func_map =
	{
		new _hook_code_func_(0, "OSTimeGet", br_OSTimeGet, 1),
        new _hook_code_func_(0, "fread", br_fread, 1),
        new _hook_code_func_(0, "memcpy", br_memcpy, 1),
        new _hook_code_func_(0, "malloc", br_malloc, 1),
        new _hook_code_func_(0, "free", br_free, 1),
        new _hook_code_func_(0, "_lcd_get_frame", br__lcd_get_frame, 1),
        new _hook_code_func_(0, "_lcd_set_frame", br__lcd_set_frame, 1),
        new _hook_code_func_(0, "_sys_judge_event", br__sys_judge_event, 1),
        new _hook_code_func_(0, "_kbd_get_status", br__kbd_get_status, 1),
        new _hook_code_func_(0, "__dcache_writeback_all", br_common, 1),
        new _hook_code_func_(0, "ap_lcd_set_frame", null, 1),
        new _hook_code_func_(0, "lcd_set_frame", br_lcd_set_frame, 1),
        new _hook_code_func_(0, "lcd_get_frame", br_lcd_get_frame, 1),
        new _hook_code_func_(0, "delay_ms", null, 1),
        new _hook_code_func_(0, "lcd_get_bpp", null, 1),
        new _hook_code_func_(0, "lcd_get_cframe", null, 1),
        new _hook_code_func_(0, "lcd_flip", null, 1),
		{0, "kbd_get_key", ((object*)0), 1},
		{0, "kbd_get_status", ((object*)0), 1},
		{0, "open_gui_key_msg", ((object*)0), 1},
		{0, "tv_get_openflag", ((object*)0), 1},
		{0, "tv_set_openflag", ((object*)0), 1},
		{0, "tv_get_closeflag", ((object*)0), 1},
		{0, "tv_set_closeflag", ((object*)0), 1},
		{0, "tv_disable_switch", ((object*)0), 1},
		{0, "tv_enable_switch", ((object*)0), 1},
		{0, "Read_Acc0", ((object*)0), 1},
		{0, "Memsic_SerialCommInit", ((object*)0), 1},
		{0, "Read_Acc", ((object*)0), 1},
		{0, "Custom_Memsic_test", ((object*)0), 1},
		{0, "Get_X", ((object*)0), 1},
		{0, "Get_Y", ((object*)0), 1},
		{0, "sys_judge_event", ((object*)0), 1},
		{0, "SysDisableBkLight", ((object*)0), 1},
		{0, "SysEnableShutDownPower", ((object*)0), 1},
		{0, "SysDisableCloseBkLight", ((object*)0), 1},
		{0, "_kbd_get_key", ((object*)0), 1},
		{0, "_waveout_open", ((object*)0), 1},
		{0, "_waveout_set_volume", br_waveout_set_volume, 1},
		{0, "jz_pm_pllconvert", ((object*)0), 1},
		{0, "strncasecmp", ((object*)0), 1},
		{0, "sys_get_ccpmp_config", ((object*)0), 1},
		{0, "vxGoHome", ((object*)0), 1},
		{0, "cmGetSysModel", ((object*)0), 1},
		{0, "cmGetSysVersion", ((object*)0), 1},
		{0, "fsys_fopen_flash", ((object*)0), 1},
		{0, "fsys_fclose_flash", ((object*)0), 1},
		{0, "get_dl_handle", ((object*)0), 1},
		{0, "get_game_vol", ((object*)0), 1},
		{0, "get_current_language", br_get_current_language, 1},
		{0, "fsys_fopen", br_fsys_fopen, 1},
		{0, "fsys_fclose", br_fsys_fclose, 1},
		{0, "fsys_fread", br_fsys_fread, 1},
		{0, "fsys_remove", ((object*)0), 1},
		{0, "fsys_fwrite", br_fsys_fwrite, 1},
		{0, "fsys_fseek", br_fsys_fseek, 1},
		{0, "fsys_ftell", br_fsys_ftell, 1},
		{0, "fsys_feof", br_fsys_feof, 1},
		{0, "fsys_ferror", ((object*)0), 1},
		{0, "fsys_clearerr", ((object*)0), 1},
		{0, "fsys_findfirst", ((object*)0), 1},
		{0, "fsys_findnext", ((object*)0), 1},
		{0, "fsys_findclose", ((object*)0), 1},
		{0, "fsys_mkdir", ((object*)0), 1},
		{0, "fsys_rename", ((object*)0), 1},
		{0, "fsys_flush_cache", ((object*)0), 1},
		{0, "fsys_RefreshCache", ((object*)0), 1},
		{0, "fsys_fopenW", br_fsys_fopenW, 1},
		{0, "fsys_fcloseW", ((object*)0), 1},
		{0, "fsys_removeW", ((object*)0), 1},
		{0, "fsys_renameW", ((object*)0), 1},
		{0, "USB_Connect", ((object*)0), 1},
		{0, "USB_No_Connect", ((object*)0), 1},
		{0, "tv_open", ((object*)0), 1},
		{0, "tv_close", ((object*)0), 1},
		{0, "isTVON", ((object*)0), 1},
		{0, "pcm_ioctl", ((object*)0), 1},
		{0, "mdelay", ((object*)0), 1},
		{0, "HP_Mute_sw", ((object*)0), 1},
		{0, "pcm_can_write", ((object*)0), 1},
		{0, "waveout_open", br_waveout_open, 1},
		{0, "waveout_close_at_once", ((object*)0), 1},
		{0, "waveout_write", br_waveout_write, 0},
		{0, "waveout_close", br_waveout_close, 1},
		{0, "waveout_can_write", br_waveout_can_write, 0},
		{0, "waveout_set_volume", br_waveout_set_volume, 1},
		{0, "av_reg_object", ((object*)0), 1},
		{0, "av_unreg_object", ((object*)0), 1},
		{0, "av_queue_get", ((object*)0), 1},
		{0, "av_uft8_2_unicode", ((object*)0), 1},
		{0, "av_resize_packet", ((object*)0), 1},
		{0, "av_upper_4cc", ((object*)0), 1},
		{0, "av_begin_thread", ((object*)0), 1},
		{0, "av_end_thread", ((object*)0), 1},
		{0, "av_create_sem", ((object*)0), 1},
		{0, "av_wait_sem", ((object*)0), 1},
		{0, "av_wait_sem2", ((object*)0), 1},
		{0, "av_give_sem", ((object*)0), 1},
		{0, "av_destroy_sem", ((object*)0), 1},
		{0, "av_create_flag", ((object*)0), 1},
		{0, "av_wait_flag", ((object*)0), 1},
		{0, "av_give_flag", ((object*)0), 1},
		{0, "av_destroy_flag", ((object*)0), 1},
		{0, "av_delay", ((object*)0), 1},
		{0, "av_queue_init", ((object*)0), 1},
		{0, "av_queue_flush", ((object*)0), 1},
		{0, "av_queue_abort", ((object*)0), 1},
		{0, "av_queue_end", ((object*)0), 1},
		{0, "av_queue_put", ((object*)0), 1},
		{0, "dl_load", ((object*)0), 1},
		{0, "dl_free", ((object*)0), 1},
		{0, "dl_res_open", ((object*)0), 1},
		{0, "dl_res_get_size", ((object*)0), 1},
		{0, "dl_res_get_data", ((object*)0), 1},
		{0, "dl_res_close", ((object*)0), 1},
		{0, "dl_get_proc", ((object*)0), 1},
		{0, "memset", br_memset, 1},
		{0, "abort", ((object*)0), 1},
		{0, "fprintf", ((object*)0), 1},
		{0, "fseek", br_fseek, 1},
		{0, "fwrite", ((object*)0), 1},
		{0, "printf", ((object*)0), 1},
		{0, "realloc", br_realloc, 1},
		{0, "sprintf", br_sprintf, 1},
		{0, "sscanf", ((object*)0), 1},
		{0, "vsprintf", ((object*)0), 1},
		{0, "GUI_Exec", ((object*)0), 1},
		{0, "GUI_Lock", ((object*)0), 1},
		{0, "GUI_TIMER_Create", ((object*)0), 1},
		{0, "GUI_TIMER_Delete", ((object*)0), 1},
		{0, "GUI_TIMER_SetPeriod", ((object*)0), 1},
		{0, "GUI_TIMER_Restart", ((object*)0), 1},
		{0, "LCD_Color2Index", ((object*)0), 1},
		{0, "LCD_GetXSize", ((object*)0), 1},
		{0, "LCD_GetYSize", ((object*)0), 1},
		{0, "WM_CreateWindow", ((object*)0), 1},
		{0, "WM_DeleteWindow", ((object*)0), 1},
		{0, "WM_SelectWindow", ((object*)0), 1},
		{0, "WM_DefaultProc", ((object*)0), 1},
		{0, "WM__SendMessage", ((object*)0), 1},
		{0, "WM_SetFocus", ((object*)0), 1},
		{0, "U8TOU32", ((object*)0), 1},
		{0, "__icache_invalidate_all", br_common, 1},
		{0, "LcdGetDisMode", ((object*)0), 1},
		{0, "free_irq", ((object*)0), 1},
		{0, "spin_lock_irqsave", ((object*)0), 1},
		{0, "spin_unlock_irqrestore", ((object*)0), 1},
		{0, "detect_clock", ((object*)0), 1},
		{0, "udelay", ((object*)0), 1},
		{0, "serial_putc", ((object*)0), 1},
		{0, "serial_puts", ((object*)0), 1},
		{0, "serial_getc", ((object*)0), 1},
		{0, "TaskMediaFunStop", ((object*)0), 1},
		{0, "StartSwTimer", ((object*)0), 1},
		{0, "GetTickCount", br_GetTickCount, 1},
		{0, "OSCPUSaveSR", ((object*)0), 1},
		{0, "OSCPURestoreSR", ((object*)0), 1},
		{0, "OSFlagPost", ((object*)0), 1},
		{0, "OSQCreate", ((object*)0), 1},
		{0, "OSSemDel", ((object*)0), 0},
		{0, "OSSemPend", br_OSSemPend, 0},
		{0, "OSSemPost", br_OSSemPost, 0},
		{0, "OSSemCreate", br_OSSemCreate, 1},
		{0, "OSTaskCreate", br_OSTaskCreate, 1},
		{0, "OSTaskDel", ((object*)0), 1},
		{0, "OSTimeDly", br_OSTimeDly, 0},
		{0, "U8TOU16", ((object*)0), 1},
		{0, "_tcscmp", ((object*)0), 1},
		{0, "_tcscpy", ((object*)0), 1},
		{0, "__to_unicode_le", ((object*)0), 1},
		{0, "__to_locale_ansi", br__to_locale_ansi, 1},
		{0, "udc_attached", ((object*)0), 1}
	};

	internal static void debugCallFunc(uc_engine uc, string name, ulong address)
	{
		uint ra;
		uc_reg_read(uc, UC_MIPS_REG_RA,out ra);
	#if _WIN32
		uint tid = GetCurrentThreadId();
	#else
		uint tid = pthread_self();
	#endif
		Console.Write("T:{0:x}, {1:D}\t{2:x8} {3}\n", tid, SDL_GetTicks64(), ra, name);
	}

    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line could not be converted:
    //public static pthread_mutex_t hook_code_mutex = ((struct pthread_mutex_t_ *)(uint) -1);
    public static System.Threading.Mutex hook_code_mutex = new System.Threading.Mutex();
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int hook_code_debugger = 0;

	internal static void hook_code(uc_engine uc, ulong address, uint size, object user_data)
	{


//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: for (int j = 0; j < sizeof(_hook_code_func_map) / sizeof(_hook_code_func_map[0]); ++j)
		for (int j = 0; j < _hook_code_func_map.Length; ++j)
		{
			if (_hook_code_func_map[(int)j].offset == address)
			{
				if (_hook_code_func_map[(int)j].func != null)
				{
					if (_hook_code_func_map[(int)j].@lock != 0)
					{
						pthread_mutex_lock(hook_code_mutex);
					}
					_hook_code_func_map[(int)j].func(uc);
					_hook_code_func_map[(int)j].trigger_times++;

					if (_hook_code_func_map[(int)j].@lock != 0)
					{
						pthread_mutex_unlock(hook_code_mutex);
					}

					if (false)
					{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: for (int i = 0; i < sizeof(_hook_code_func_map) / sizeof(_hook_code_func_map[0]); ++i)
						for (int i = 0; i < _hook_code_func_map.Length; ++i)
						{
							if (_hook_code_func_map[(int)i].func != null)
							{
								Console.Write("times: {0,10:D} \t{1}\n", _hook_code_func_map[(int)i].trigger_times, _hook_code_func_map[(int)i].name);
							}
						}
					}

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//				static int debugger = 0;
					if (hook_code_debugger!=0)
					{
						debugCallFunc(uc, _hook_code_func_map[(int)j].name, address);
						//dumpREG(uc);
					}
				}
				else
				{
					Console.Write("-----------------br_none:{0}----------------\n", _hook_code_func_map[(int)j].name);
					dumpREG(uc);
					//dumpStackCall(uc);
					//dumpAsm(uc);
					Environment.Exit(0);
				}
				break;
			}
		}
	}

	public static void uc_cb_hookintr(uc_engine uc, uint intno, object user_data)
	{
		app _app = (app)user_data;
	}

	internal static void hook_block(uc_engine uc, ulong address, uint size, object user_data)
	{
        //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
        //ORIGINAL LINE: printf(">>> Tracing basic block at 0x%" PRIx64 ", block size = 0x%x\n", address, size);
       // Console.Write(">>> Tracing basic block at 0x%" PRIx64 ", block size = 0x{1:x}\n", address, size);
        Console.Write(">>> Tracing basic block at 0x%, block size = 0x{1:x}\n", address, size);
    }

	internal static void hooks_init(uc_engine uc, app _app)
	{
		for (int i = 0; i < _app.import_count; ++i)
		{
			app_import_entry entry = _app.import_data[(int)i];
			string name = toString( entry.name);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: for (int j = 0; j < sizeof(_hook_code_func_map) / sizeof(_hook_code_func_map[0]); ++j)
			for (int j = 0; j < _hook_code_func_map.Length; ++j)
			{
				if (string.Compare(name, _hook_code_func_map[(int)j].name) == 0)
				{
					_hook_code_func_map[(int)j].offset = entry.offset;
					_hook_code_func_map[(int)j].trigger_times = 0;
					break;
				}
			}
		}

		uc_err err = new uc_err();
		uc_hook trace = new uc_hook();
		ulong offset_begin = _app.import_data[0].offset;
		ulong offset_end = _app.import_data[_app.import_count - 1].offset;
		err = uc_hook_add(uc, trace, UC_HOOK_CODE, hook_code, (object)_app, offset_begin, offset_end, 0);
		if (err != UC_ERR_OK)
		{
			Console.Write("add hook err {0:D} ({1})\n", err, uc_strerror(err));
			return;
		}
	}

	public static void _kbd_get_status(KEY_STATUS* ks)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memcpy' has no equivalent in C#:
		memcpy(ks, s_KayStatus, sizeof(KEY_STATUS));
	}
    public enum SDL_Keycode
    {
        SDLK_0,
        SDLK_1, SDLK_w, SDLK_UP, SDLK_s,
        SDLK_DOWN,
        SDLK_a,
        SDLK_LEFT,
        SDLK_d, SDLK_RIGHT, SDLK_k, SDLK_l, SDLK_o, SDLK_i,
    }

    public static void updateKeyStatus(int type, SDL_Keycode code)
	{
		switch (code)
		{
		case SDL_Keycode.SDLK_0:
			updateKey(type, DefineConstants.CONTROL_BUTTON_SELECT);
			// select
			break;
		case SDL_Keycode.SDLK_1:
			updateKey(type, DefineConstants.CONTROL_BUTTON_START);
			// start
			break;
		case SDL_Keycode.SDLK_w:
		case SDL_Keycode.SDLK_UP: // ��
			updateKey(type, DefineConstants.CONTROL_DPAD_UP);
			break;
		case SDL_Keycode.SDLK_s:
		case SDL_Keycode.SDLK_DOWN: // ��
			updateKey(type, DefineConstants.CONTROL_DPAD_DOWN);
			break;
		case SDL_Keycode.SDLK_a:
		case SDL_Keycode.SDLK_LEFT: // ��
			updateKey(type, DefineConstants.CONTROL_DPAD_LEFT);
			break;
		case SDL_Keycode.SDLK_d:
		case SDL_Keycode.SDLK_RIGHT: // ��
			updateKey(type, DefineConstants.CONTROL_DPAD_RIGHT);
			break;
		case SDL_Keycode.SDLK_k: // a
			updateKey(type, DefineConstants.CONTROL_BUTTON_A);
			break;
		case SDL_Keycode.SDLK_l: // b
			updateKey(type, DefineConstants.CONTROL_BUTTON_B);
			break;
		case SDL_Keycode.SDLK_o: //y
			updateKey(type, DefineConstants.CONTROL_BUTTON_Y);
			break;
		case SDL_Keycode.SDLK_i: //x
			updateKey(type, DefineConstants.CONTROL_BUTTON_X);
			break;
		default:
			break;
		}
	}



	public static KEY_STATUS s_KayStatus = new KEY_STATUS();

	internal static void updateKey(int press, uint key)
	{
		if (press != 0)
		{
			s_KayStatus.status |= (1 << (int)key);
		}
		else
		{
			s_KayStatus.status &= (~(1 << (int)key));
		}
	}
	public static void startDingoo()
	{
		Console.Write("startDingoo\n");

		pthread_t tid = new pthread_t();
		int ret = pthread_create(tid, null, dingooRun, null);
		if (ret != 0)
		{
			Console.Write("pthread_create dingooRun failed\n");
			Debug.Assert(0);
		}
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static FILE[] __iob_func_files = {*(stdin), *(stdout), *(stderr)};

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

	public static FILE[] __iob_func()
	{
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//		static FILE files[] = { *(stdin), *(stdout), *(stderr) };
			return __iob_func_files;
	}

	//#define APP_NAME "\\7days"

	public static uint s_AppDataAddr = 0;
	public static uint s_AppDataBuffSize = 0;
	public static object s_AppDataBuff = 0;
	public static app s_app = null;

	public static app loadApp()
	{
		app _app = null;
		string tempPath = new string(new char[1024]);
		tempPath = string.Format("{0}.app", DefineConstants.APP_NAME);
		FILE tempFile = fopen(tempPath, "rb");
		if (tempFile == null)
		{
			Console.Write("Error: Couldn't open \"{0}.app\".\n", "7day");
			return null;
		}
		fseek(tempFile, 0, SEEK_END);
		ushort tempBodyLen = ftell(tempFile);
		fseek(tempFile, 0, SEEK_SET);

		_app = app_create(tempFile, tempBodyLen);
		if (_app == null)
		{
			Console.Write("Error: Couldn't create app struct.\n");
			return null;
		}

		//fclose(tempFile);

		return _app;
	}

    public static void freeApp(app pstApp)
	{
		app_delete(pstApp);
	}

	internal static uint breakpoint = 0x80A4A218;
	internal static uint start_debug = 0;
	public static FILE fp = stdout;
	public static int use_stdout = 0;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int tryInitLog_init_debug_log = 0;

	public static void tryInitLog()
	{
		if (use_stdout != 0)
		{
			return;
		}

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
	//	static int init_debug_log = 0;
		if (((int)tryInitLog_init_debug_log) == 0)
		{
			fp = fopen("D://Dingoo//hook_code_debug.txt", "w+");
			if (fp != null)
			{
				tryInitLog_init_debug_log = 1;
			}
		}
	}

	public static void hook_code_dingoo_debug(uc_engine uc, ulong address, uint size, object user_data)
	{
		//debug
		dingoo_debug(uc);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int hook_code_debug_print_flag = 1;


	public static void hook_code_debug(uc_engine uc, ulong address, uint size, object user_data)
	{
		if (breakpoint == address)
		{
			start_debug = 1;
		}

		if (start_debug == 0)
		{
			return;
		}

		return;

//		tryInitLog();

//		if (size <= 4)
//		{
//			cs_insn insn;
//			uint binary;
//			uint count;
//			csh handle = 0;
//			string str = new string(new char[60]);
//			uint pc;

//			if (cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32, handle) != CS_ERR_OK)
//			{
//				Console.Write("debug cs_open() fail.");
//				Environment.Exit(1);
//			}

//			uc_reg_read(uc, UC_MIPS_REG_PC, pc);
//			uc_mem_read(uc, address, binary, size);
//			count = cs_disasm(handle, (byte) & binary, size, address, 1, insn);
//			if (count > 0)
//			{
//				for (uint j = 0; j < count; j++)
//				{
//	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
//	//				static int print_flag = 1;
//					if (hook_code_debug_print_flag)
//					{
//						if (fp != null)
//						{
//							fprintf(fp, "%lx %08X:    %08x    %s\t%s\n", SDL_GetTicks64(), pc, binary, insn[j].mnemonic, insn[j].op_str);
//							dumpREG2File(uc, fp);
//							//dumpStackCall(uc, 0xa0000000);
//							fflush(fp);
//						}
//						//dumpREG(uc);
//						//printf("%08X:    %08x    %s\t%s\n", pc, binary, insn[j].mnemonic, insn[j].op_str);
//					}
//				}
//				cs_free(insn, count);
//			}
//			else
//			{
//				if (fp != null)
//				{
//					fprintf(fp, "%08X:     %08x    0x%" PRIXPTR "    %d]> ", pc, binary, address, size);
//					fflush(fp);
//				}
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
////ORIGINAL LINE: printf("[PC:0x%X, mem:0x%" PRIXPTR ", size:%d]> ", pc, address, size);
//				Console.Write("[PC:0x{0:X}, mem:0x%" PRIXPTR ", size:{2:D}]> ", pc, address, size);
//			}
//			cs_close(handle);
		//}
	}

	internal static void hook_mem_valid(uc_engine uc, uc_mem_type type, ulong address, int size, long value, object user_data)
	{
		tryInitLog();

		//fprintf(fp, ">>> Tracing mem_valid mem_type:%s at 0x%" PRIx64 ", size:0x%x, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		if (type == UC_MEM_READ && size <= 4)
		{
			uint v;
			uint pc;
			uc_mem_read(uc,(uint)address,out v, size);
			uc_reg_read(uc, UC_MIPS_REG_PC,out pc);
			//fprintf(fp, "PC:0x%X,read:0x%X\n", pc, v);
		}
	}

	internal static bool hook_mem_invalid(uc_engine uc, uc_mem_type type, ulong address, int size, long value, object user_data)
	{
		tryInitLog();
		//fprintf(fp, ">>> Tracing mem_invalid mem_type:%s at 0x%" PRIx64 ", size:0x%x, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		dumpREG2File(uc, fp);
		dumpAsm(uc);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf(">>> Tracing mem_invalid mem_type:%s at 0x%" PRIx64 ", size:0x%x, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		//Console.Write(">>> Tracing mem_invalid mem_type:{0} at 0x%" PRIx64 ", size:0x{2:x}, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		dumpREG(uc);
		return false;
	}

	public static bool uc_cb_hookinsn_invalid(uc_engine uc, object user_data)
	{
		Console.Write(">>> Tracing uc_cb_hookinsn_invalid \n");
		dumpREG(uc);
		return false;
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
private static int hook_block_logger = 0;


//	internal static void hook_block(uc_engine uc, ulong address, uint size, object user_data)
//	{
//	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
//	//	static int logger = 0;
//		if (hook_block_logger)
//		{
//			//uint64_t tempTicks = GetTickCount64();
//			ulong tempTicks = 0;
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
////ORIGINAL LINE: printf("%lld 0x%" PRIx64 " 0x%x\n", tempTicks, address, size);
//			Console.Write("{0:D} 0x%" PRIx64 " 0x{2:x}\n", tempTicks, address, size);
//		}
//	}

	public static void hook_code_hook_appMain(uc_engine uc, ulong address, uint size, object user_data)
	{
		Console.Write(">>> Tracing hook_code_hook_appMain \n");

		uc_err err = new uc_err();
		string pBuf = new string(new char[MAX_PATH]);
		GetCurrentDirectory(MAX_PATH, pBuf);
		//string appPath = string(pBuf) + string(APP_NAME) + ".app";
		string appPath = (string)DefineConstants.APP_NAME + ".app";
		uint respathPtr = vm_malloc(64);

		err = uc_mem_write(uc, respathPtr, String2WString(appPath), 64);
		//if (err != null)
		//{
		//	Console.Write("Failed on uc_mem_write() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
		//	Environment.Exit(1);
		//}
		err = uc_reg_write(uc, UC_MIPS_REG_A0, respathPtr);
		//if (err != null)
		//{
		//	Console.Write("Failed on uc_reg_write() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
		//	Environment.Exit(1);
		//}

		// AppMainֻhookһ�Σ���ȥ��ɾ��hook
		uc_hook hh = (uc_hook)user_data;
		err = uc_hook_del(uc, hh);
		//if (err != null)
		//{
		//	Console.Write("Failed on uc_hook_del() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
		//	Environment.Exit(1);
		//}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
		free(user_data);
	}


	public static uc_engine initDingoo()
	{
		uc_engine uc;
		uc_err err = new uc_err();
		uc_hook trace = new uc_hook();

		err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, uc);
		if (err != null)
		{
			Console.Write("Failed on uc_open() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			return null;
		}

		//app* _app = loadApp();
		app _app = null;
		string tempPath = new string(new char[1024]);
		/*char pBuf[MAX_PATH];
		GetCurrentDirectory(MAX_PATH, pBuf);*/
		//sprintf(tempPath, "%s%s.app", pBuf, APP_NAME);

		tempPath = string.Format("{0}.app", DefineConstants.APP_NAME);
		FILE tempFile = fopen(tempPath, "rb");
		if (tempFile == null)
		{
			Console.Write("Error: Couldn't open \"{0}.app\".\n", "7day");
			return null;
		}
		fseek(tempFile, 0, SEEK_END);
		ushort tempBodyLen = ftell(tempFile);
		fseek(tempFile, 0, SEEK_SET);

		_app = app_create(tempFile, tempBodyLen);
		if (_app == null)
		{
			Console.Write("Error: Couldn't create app struct.\n");
			return null;
		}

		fclose(tempFile);
		uint size = _app.bin_size;

		s_AppDataAddr = _app.origin;
		s_AppDataBuffSize = size;
		s_AppDataBuff = _app.bin_data;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: s_app = _app;
		s_app = _app;

		err = uc_mem_map_ptr(uc, s_AppDataAddr, s_AppDataBuffSize, UC_PROT_ALL, s_AppDataBuff);
		if (err != null)
		{
			Console.Write("Failed mem map: {0:D} ({1})\n", err, uc_strerror(err));
			uc_close(uc);
			return null;
		}

		err = bridge_init(uc, _app);
		if (err != null)
		{
			Console.Write("Failed bridge_init(): {0:D} ({1})\n", err, uc_strerror(err));
			uc_close(uc);
			return null;
		}

		//uc_hook_add(uc, &trace, UC_HOOK_BLOCK, hook_block, NULL, 1, 0);
		uc_hook_add(uc, trace, UC_HOOK_CODE, hook_code_debug, (object)_app, 1, 0);
		//uc_hook_add(uc, &trace, UC_HOOK_INSN_INVALID, uc_cb_hookinsn_invalid, NULL, 1, 0);
		//uc_hook_add(uc, &trace, UC_HOOK_MEM_INVALID, hook_mem_invalid, NULL, 1, 0, 0);
		//uc_hook_add(uc, &trace, UC_HOOK_MEM_VALID, hook_mem_valid, NULL, 1, 0);

		uc_hook_add(uc, trace, UC_HOOK_CODE, hook_code_dingoo_debug, null, 0x80B0F060, 0x80B0F060);

		if (InitVmMem(uc, _app) != 0)
		{
			Console.Write("Failed InitVmMem()\n");
			uc_close(uc);
			return null;
		}

		if (InitFb(uc) != 0)
		{
			Console.Write("Failed InitFb()\n");
			uc_close(uc);
			return null;
		}

		uint value = 0;
		uc_reg_write(uc, UC_MIPS_REG_ZERO, value);

		uint appMainEntry = 0;
		for (int i = 0; i < _app.export_count; i++)
		{
			if (string.Compare(_app.export_data[(int)i].name, "AppMain") == 0)
			{
				appMainEntry = _app.export_data[(int)i].offset;
				break;
			}
		}

		if (appMainEntry == 0)
		{
			Console.Write("Failed load appMainEntry \n");
			Environment.Exit(1);
		}

		err = uc_reg_write(uc, UC_MIPS_REG_RA, appMainEntry);
		if (err != null)
		{
			Console.Write("Failed on uc_reg_write() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		uc_hook hh = (uc_hook)malloc(sizeof(uc_hook));
		//hook appMainEntry
		err = uc_hook_add(uc, hh, UC_HOOK_CODE, hook_code_hook_appMain, (object)hh, appMainEntry, appMainEntry, 0);
		if (err != UC_ERR_OK)
		{
			Console.Write("add hook hook_code_hook_appMain err {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		uint malloc_lcd_buff = 0;
		err = uc_reg_write(uc, UC_MIPS_REG_A1, malloc_lcd_buff);
		if (err != null)
		{
			Console.Write("Failed on uc_reg_write() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		err = uc_emu_start(uc, _app.bin_entry, 0xFFFFFFFF, 0, 0);
		if (err != null)
		{
			Console.Write("Failed on uc_emu_start() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		return uc;
	end:
		uc_close(uc);
		return null;
	}

	public static object dingooRun(object data)
	{
		uc_engine __uc = initDingoo();
		return 0;
	}


	public static int InitFb(uc_engine uc)
	{
		uc_err err = uc_mem_map_ptr(uc, VM_LCD_FB_ADDRESS, sizeof(byte), uc_prot.UC_PROT_ALL, s_LcdFrameBufferPtr);
		if (err != UC_ERR_OK)
		{
			Console.Write("Failed mem map s_LcdFrameBufferPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		return 0;
	}

	public static uint _lcd_get_frame()
	{
		return VM_LCD_FB_ADDRESS;
	}

	public static object getFramebuffPtr()
	{
		return s_LcdFrameBufferPtr;
	}

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)


	public static uint VM_LCD_FB_ADDRESS = 0x90000000;
	public static byte* s_LcdFrameBufferPtr ;


	/*
	uint32_t s_VmLcdFrameBufferPtr = NULL;
	void* s_LcdFrameBufferPtr = NULL;
	
	int InitFb(uc_engine* uc, app* _app)
	{
		uint32_t p = vm_malloc(sizeof(uint16_t) * SCREEN_WIDTH * SCREEN_HEIGHT);
		s_LcdFrameBufferPtr = toHostPtr(p);
	
		if (!s_LcdFrameBufferPtr)
		{
			printf("Failed InitFb(), p = 0x%08x\n", p);
			assert(0);
		}
	
		s_VmLcdFrameBufferPtr = p;
	
		return 0;
	}
	
	uint32_t _lcd_get_frame(void)
	{
		return s_VmLcdFrameBufferPtr;
	}
	
	void * getFramebuffPtr(void)
	{
		return s_LcdFrameBufferPtr;
	}
	*/
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

	internal static SDL_Window window = null;
	internal static SDL_Keycode isKeyDown = SDLK_UNKNOWN;


	public static uint fps_lasttime = SDL_GetTicks(); //the last recorded time.
	public static uint fps_current; //the current FPS.
	public static uint fps_frames = 0; //frames passed since the last recorded fps.

	public static void guiDrawBitmap(ref ushort bmp, int x, int y, int w, int h)
	{
		SDL_Surface surface = SDL_GetWindowSurface(window);
		/*
		if (SDL_MUSTLOCK(surface))
		{
		    if (SDL_LockSurface(surface) != 0)
		    {
		        printf("SDL_LockSurface err\n");
		    }
		}
		*/
		for (int j = 0; j < h; j++)
		{
			for (int i = 0; i < w; i++)
			{
				int xx = (int)x + i;
				int yy = (int)y + j;
				if (xx < 0 || yy < 0 || xx >= DefineConstants.SCREEN_WIDTH || yy >= DefineConstants.SCREEN_HEIGHT)
				{
					continue;
				}
				ushort color = (bmp + (xx + yy * DefineConstants.SCREEN_WIDTH));
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: uint* p = (uint*)(((byte*)surface->pixels) + surface->pitch * yy) + xx;
				uint p = (uint)(((byte)surface.pixels) + surface.pitch * yy) + xx;
				p = SDL_MapRGB(surface.format, ((((uint)color >> 11) << 3) & 0xff), ((((uint)color >> 5) << 2) & 0xff), (((uint)color << 3) & 0xff));
			}
		}
		/*
		if (SDL_MUSTLOCK(surface))
		{
		    SDL_UnlockSurface(surface);
		}
		*/
		if (SDL_UpdateWindowSurface(window) != 0)
		{
			Console.Write("SDL_UpdateWindowSurface err\n");
		}

		fps_frames++;
		if (fps_lasttime < SDL_GetTicks() - DefineConstants.FPS_INTERVAL * 1000)
		{
			fps_lasttime = SDL_GetTicks();
			fps_current = fps_frames;
			fps_frames = 0;
			Console.Write("fps:{0:D}\n", fps_current);
		}
	}

	public static void updateFb()
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: ushort* fb = (ushort*)getFramebuffPtr();
		ushort fb = (ushort)getFramebuffPtr();
		guiDrawBitmap(ref fb, 0, 0, DefineConstants.SCREEN_WIDTH, DefineConstants.SCREEN_HEIGHT);
	}

	public static void loop()
	{
		SDL_Event ev = new SDL_Event();
		bool isLoop = true;

		while (isLoop)
		{
			while (SDL_WaitEvent(ev))
			{
				if (ev.type == SDL_QUIT)
				{
					isLoop = false;
					break;
				}
				switch (ev.type)
				{
				case SDL_KEYDOWN:
					if (isKeyDown == SDLK_UNKNOWN)
					{
						isKeyDown = ev.key.keysym.sym;
						updateKeyStatus(1, ev.key.keysym.sym);
					}
					break;
				case SDL_KEYUP:
					if (isKeyDown == ev.key.keysym.sym)
					{
						isKeyDown = SDLK_UNKNOWN;
						updateKeyStatus(0, ev.key.keysym.sym);
					}
					break;
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONDOWN:
					break;
				case SDL_MOUSEBUTTONUP:
					break;
				default:
					break;
				}
			}
		}
	}

	static int Main(string[] args)
	{
		if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
		{
			Console.Write("SDL could not initialize! SDL_Error: {0}\n", SDL_GetError());
			return -1;
		}

		window = SDL_CreateWindow("dingoo-emu", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DefineConstants.SCREEN_WIDTH, DefineConstants.SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
		if (window == null)
		{
			Console.Write("Window could not be created! SDL_Error: {0}\n", SDL_GetError());
			return -1;
		}

		startDingoo();

		loop();
        return -1;
    }
	/*
	ʹ��һ�������߳�ģ��Ӳ��������
	*/



	public static object MixerThreadRun(object data)
	{
        return null;
//		waveout_args args = (waveout_args)data;

//		g_Volume = args.volume;

//		uint ret = -1;

//		int audio_rate = args.sample_rate; // MIX_DEFAULT_FREQUENCY;
//		ushort audio_format = convertFormat(args.format);
//		int audio_channels = MIX_DEFAULT_CHANNELS;

//		/* Open the audio device */
//		if (ret = Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0)
//		{
//			SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
//			Environment.Exit(2);
//		}

//		Mix_QuerySpec(audio_rate, audio_format, audio_channels);
//		SDL_Log("Opened audio at %d Hz %d bit%s %s", audio_rate, (audio_format & 0xFF), (SDL_AUDIO_ISFLOAT(audio_format) ? " (float)" : ""), (audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono");

//		while (true)
//		{
//			switch (g_mixer_state)
//			{
//			case DefineConstants.MIXER_STATE_PREPARED:
//			{
//				//g_MixerBuff = convertInsert(audio_rate / args->sample_rate * 1.0f, g_MixerBuff, g_MixerCount);
//				wave.abuf = (byte)g_MixerBuff;
//				wave.alen = g_MixerCount;
//				wave.volume = args.volume;
//				wave.allocated = 0;
//				if (g_Volume != wave.volume)
//				{
//					wave.volume = g_Volume;
//				}

//				/* Play and then exit */
//				uint ret = Mix_PlayChannel(-1, wave, 0);

//				g_mixer_state = DefineConstants.MIXER_STATE_PLAYING;

//				break;
//			}
//			case DefineConstants.MIXER_STATE_PLAYING:
//			{
//				if (g_Volume != args.volume)
//				{
//					args.volume = g_Volume;
//					Mix_Volume(-1, g_Volume);
//				}

//				if (Mix_Playing(-1) > 0)
//				{
//					SDL_Delay(1);
//				}
//				else
//				{
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
//					free(g_MixerBuff);
//					g_MixerBuff = null;

//					g_mixer_state = DefineConstants.MIXER_STATE_IDLE;
//				}

//				break;
//			}
//			case DefineConstants.MIXER_STATE_IDLE:
//				SDL_Delay(1);
//				break;
//			default:
//				SDL_Delay(1);
//				break;
//			}
//		}
	}
	public static uint MixerWriteBuff(byte* buffer, uint count)
	{
		if (g_mixer_state == DefineConstants.MIXER_STATE_IDLE)
		{
			g_MixerBuff = buffer;
			g_MixerCount = (uint)count;

			g_mixer_state = DefineConstants.MIXER_STATE_PREPARED;
		}

		return 1;
	}
	public static uint MixerPlaying()
	{
		if (g_mixer_state != DefineConstants.MIXER_STATE_IDLE)
		{
			return 0;
		}
		return 1;
	}
	public static void MixerSetVolume(uint vol)
	{
		g_Volume = vol;
	}




	internal static int g_mixer_state = DefineConstants.MIXER_STATE_IDLE;
	internal static string g_MixerBuff = null;
	internal static uint g_MixerCount = 0;
	internal static uint g_Volume = 70;
	public static Mix_Chunk wave = new Mix_Chunk();

	public static ushort convertFormat(ushort format)
	{
		switch (format)
		{
		case DefineConstants.AFMT_U8:
			return AUDIO_U8;
		case DefineConstants.AFMT_S16_LE:
			return AUDIO_S16LSB;
		default:
			return MIX_DEFAULT_FORMAT;
		}
	}

	//��ֵ
	public static string convertInsert(float percent, ref string buff, int size)
	{
		int size_real = (int)size * percent;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: sbyte *newBuff = (sbyte*)malloc(size_real);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		sbyte newBuff = (string)malloc(size_real);
		for (int i = 0; i < size_real / 2; i++)
		{
			int index = (int)(i / percent);
			if (index >= size / 2)
			{
				((ushort)newBuff)[(int)i] = ((ushort)buff)[(int)size-1];
			}
			((ushort)newBuff)[(int)i] = ((ushort)buff)[(int)index];
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'free' has no equivalent in C#:
		free(buff);

		return newBuff;
	}
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)


	public static void my_sprintf(uc_engine uc)
	{
		uint a0;
		uint a1;
		uint a2;
		uint a3;
		uint sp;

		uc_reg_read(uc, UC_MIPS_REG_A0,out a0);
		uc_reg_read(uc, UC_MIPS_REG_A1, out a1);
		uc_reg_read(uc, UC_MIPS_REG_A2, out a2);
		uc_reg_read(uc, UC_MIPS_REG_A3, out a3);

		uc_reg_read(uc, UC_MIPS_REG_SP, out sp);

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
sbyte* buffer = (sbyte*)toHostPtr((a0));
		//sbyte buffer = (string)toHostPtr((a0));
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
sbyte* format = (sbyte*)toHostPtr((a1));
		//sbyte format = (string)toHostPtr((a1));

		uint s1;
		uint s2;

		sp -= 40;

		s1 = ((uint*)toHostPtr((sp + 48)))[0];
		s2 = ((uint*)toHostPtr((sp + 52)))[0];

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: *((uint*)toHostPtr((sp + 48))) = a2;
		*(uint*)toHostPtr((sp + 48)) = a2;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: *((uint*)toHostPtr((sp + 52))) = a3;
		*(uint*)toHostPtr((sp + 52)) = a3;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
   sbyte* va = (sbyte*)toHostPtr((sp + 48));
		//sbyte va = (string)toHostPtr((sp + 48));

		uint ret;
		ret = (int)my_vsnprintf(uc, _out_buffer, buffer, uint.MaxValue, format, va);

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
*((uint*)toHostPtr((sp + 48))) = s1;
		//(uint)toHostPtr((sp + 48)) = s1;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
 *((uint*)toHostPtr((sp + 52))) = s2;
		//(uint)toHostPtr((sp + 52)) = s2;

		//printf("my_vsnprintf: buffer %s, format %s\n", buffer, format);

		uc_reg_write(uc, UC_MIPS_REG_V0, ret);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	public static void dingoo_debug(uc_engine uc)
	{
		uint a0;
		uint a1;
		uint a2;
		uint a3;
		uint sp;

		uc_reg_read(uc, UC_MIPS_REG_A0, a0);
		uc_reg_read(uc, UC_MIPS_REG_A1, a1);
		uc_reg_read(uc, UC_MIPS_REG_A2, a2);
		uc_reg_read(uc, UC_MIPS_REG_A3, a3);

		uc_reg_read(uc, UC_MIPS_REG_SP, sp);

		string buffer = new string(new char[128]);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
 sbyte* format = (sbyte*)toHostPtr((a0));
		//sbyte format = (string)toHostPtr((a0));

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
 *(uint*)toHostPtr((sp + 4)) = a1;
		//(uint)toHostPtr((sp + 4)) = a1;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
 *(uint*)toHostPtr((sp + 8)) = a2;
		//(uint)toHostPtr((sp + 8)) = a2;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
*(uint*)toHostPtr((sp + 0xc)) = a3;
		//(uint)toHostPtr((sp + 0xc)) = a3;

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
 sbyte* va = (sbyte*)toHostPtr((sp + 4));
		//sbyte va = (string)toHostPtr((sp + 4));

		uint ret;
		ret = (int)my_vsnprintf(uc, _out_buffer, ref buffer, (uint)-1, format, va);

		Console.Write("s3d_dbg: {0}", buffer);

		uint pc;
		uc_reg_read(uc, UC_MIPS_REG_RA, pc);
		uc_reg_write(uc, UC_MIPS_REG_PC, pc);
	}

	// internal secure strlen
	// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
	internal static uint _strnlen_s(sbyte* str, uint maxsize)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: Pointer arithmetic is detected on this variable, so pointers on this variable are left unchanged:
		sbyte * s;
		for (s = str; * s!=0 && maxsize--!=0; ++s)
		{
			;
		}
		return (uint)(s - str);
	}


	// internal test if char is a digit (0-9)
	// \return true if char is a digit
	internal static bool _is_digit(sbyte ch)
	{
		return (ch >= (sbyte)'0') && (ch <= (sbyte)'9');
	}


	// internal ASCII string to unsigned int conversion
	internal static uint _atoi(string[] str)
	{
		uint i = 0U;
		while (_is_digit(str[0]))
		{
			i = i * 10U + (uint)(*(str++) - '0');
		}
		return i;
	}



	// internal buffer output
	internal static void _out_buffer(sbyte character, void* buffer, uint idx, uint maxlen)
	{
		if (idx < maxlen)
		{
			((sbyte*)buffer)[idx] = character;
		}
	}

	// output function type
	public delegate void out_fct_type(sbyte character, sbyte* buffer, int idx, uint maxlen);


	// output the specified string in reverse, taking care of any zero-padding
	internal static int _out_rev(out_fct_type @out, sbyte* buffer, int idx, uint maxlen, void* buf, int len, uint width, uint flags)
	{
		int start_idx = (int)idx;
		int i;

		// pad spaces up to given width
		if (0 == (flags & (1 << 1)) && 0==(flags & (1 << 0)))
		{
			for (i = (int)len; i < width; i++)
			{
				@out((sbyte)' ', buffer, idx++, maxlen);
			}
		}

		// reverse string
		while (len != 0)
		{
			@out(((sbyte*)buf)[--len], buffer, idx++, maxlen);
		}

		// append pad spaces up to given width
		if ((flags & (1 << 1)) != 0)
		{
			while (idx - start_idx < width)
			{
				@out((sbyte)' ', buffer, idx++, maxlen);
			}
		}

		return idx;
	}

	// internal itoa format
	internal static int _ntoa_format(out_fct_type @out, sbyte* buffer, int idx, uint maxlen, sbyte* buf, int len, bool negative, uint @base, uint prec, uint width, uint flags)
	{
		// pad leading zeros
		if (((flags & (1 << 1)) == 0))
		{
			if (width != 0 && (flags & (1 << 0))!=0 && (negative || (flags & ((1 << 2) | (1 << 3))) != 0))
			{
				width--;
			}
			while ((len < prec) && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE))
			{
				buf[(int)len++] = (sbyte)'0';
			}
			while ((flags & (1 << 0))!=0 && (len < width) && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE))
			{
				buf[(int)len++] =( sbyte) '0';
			}
		}

		// handle hash
		if ((flags & (1 << 4)) != 0)
		{
			if (0==(flags & (1 << 10)) && ((int)len) != 0 && (((int)len == prec) || ((int)len == width)))
			{
				len--;
				if (((int)len) != 0 && (@base == 16U))
				{
					len--;
				}
			}
			if ((@base == 16U) && 0==(flags & (1 << 5)) && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE))
			{
				buf[(int)len++] = (sbyte)'x';
			}
			else if ((@base == 16U) && (flags & (1 << 5))!=0 && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE))
			{
				buf[(int)len++] = (sbyte)'X';
			}
			else if ((@base == 2U) && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE))
			{
				buf[(int)len++] = (sbyte)'b';
			}
			if (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE)
			{
				buf[(int)len++] = (sbyte)'0';
			}
		}

		if (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE)
		{
			if (negative)
			{
				buf[(int)len++] = (sbyte)'-';
			}
			else if ((flags & (1 << 2))!=0)
			{
				buf[(int)len++] = (sbyte)'+'; // ignore the space if the '+' exists
			}
			else if ((flags & (1 << 3))!=0)
			{
				buf[(int)len++] = (sbyte)' ';
			}
		}

		return _out_rev(@out,  buffer, idx, maxlen, buf, len, width, flags);
	}


	// internal itoa for 'long' type
	internal static int _ntoa_long(out_fct_type @out, ref string buffer, int idx, int maxlen, uint value, bool negative, uint @base, uint prec, uint width, uint flags)
	{
		string buf = new string(new char[DefineConstants.PRINTF_NTOA_BUFFER_SIZE]);
		int len = 0U;

		// no hash for 0 values
		if (value == 0)
		{
			flags &= ~(1U << 4U);
		}

		// write if precision != 0 and value is != 0
		if (!(flags & (1U << 10U)) || value != 0)
		{
			do
			{
				sbyte digit = (sbyte)(value % @base);
				buf = StringFunctions.ChangeCharacter(buf, len++, digit < 10 ? '0' + digit : ((flags & (1U << 5U)) != 0 ? 'A' : 'a') + digit - 10);
				value /= @base;
			} while (value != 0 && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE));
		}

		return _ntoa_format(@out, ref buffer, idx, maxlen, ref buf, len, negative, (uint)@base, prec, width, flags);
	}

	internal static int _ntoa_long_long(out_fct_type @out, ref string buffer, int idx, int maxlen, ulong value, bool negative, ulong @base, uint prec, uint width, uint flags)
	{
		string buf = new string(new char[DefineConstants.PRINTF_NTOA_BUFFER_SIZE]);
		int len = 0U;

		// no hash for 0 values
		if (value == 0)
		{
			flags &= ~(1U << 4U);
		}

		// write if precision != 0 and value is != 0
		if (!(flags & (1U << 10U)) || value != 0)
		{
			do
			{
				sbyte digit = (sbyte)(value % @base);
				buf = StringFunctions.ChangeCharacter(buf, len++, digit < 10 ? '0' + digit : ((flags & (1U << 5U)) != 0 ? 'A' : 'a') + digit - 10);
				value /= @base;
			} while (value != 0 && (len < DefineConstants.PRINTF_NTOA_BUFFER_SIZE));
		}

		return _ntoa_format(@out, ref buffer, idx, maxlen, ref buf, len, negative, (uint)@base, prec, width, flags);
	}


	// internal ftoa for fixed decimal floating point
	internal static int _ftoa(out_fct_type @out, ref string buffer, int idx, int maxlen, double value, uint prec, uint width, uint flags)
	{
		string buf = new string(new char[DefineConstants.PRINTF_FTOA_BUFFER_SIZE]);
		int len = 0U;
		double diff = 0.0;
		bool negative = false;
		int whole;
		double tmp;
		uint frac;

		// powers of 10
		double[] pow10 = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

		// test for special values
		if (value != value)
		{
			return _out_rev(@out, ref buffer, idx, maxlen, "nan", 3, width, flags);
		}
		if (value < -double.MaxValue)
		{
			return _out_rev(@out, ref buffer, idx, maxlen, "fni-", 4, width, flags);
		}
		if (value > double.MaxValue)
		{
			return _out_rev(@out, ref buffer, idx, maxlen, ((flags & (1 << 2)) != 0) ? "fni+" : "fni", ((flags & (1 << 2)) != 0) ? 4U : 3U, width, flags);
		}

		// test for very large values
		// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
		if ((value > DefineConstants.PRINTF_MAX_FLOAT) || (value < -DefineConstants.PRINTF_MAX_FLOAT))
		{
	#if PRINTF_SUPPORT_EXPONENTIAL
			return _etoa(@out, buffer, idx, maxlen, value, prec, width, flags);
	#else
			return 0;
	#endif
		}

		// test for negative
		if (value < 0)
		{
			negative = true;
			value = 0 - value;
		}

		// set default precision, if not set explicitly
		if (((flags & (1 << 10)) == 0))
		{
			prec = DefineConstants.PRINTF_DEFAULT_FLOAT_PRECISION;
		}
		// limit precision to 9, cause a prec >= 10 can lead to overflow errors
		while ((len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U))
		{
			buf = StringFunctions.ChangeCharacter(buf, len++, '0');
			prec--;
		}

		whole = (int)value;
		tmp = (value - whole) * pow10[prec];
		frac = (uint)tmp;
		diff = tmp - frac;

		if (diff > 0.5)
		{
			++frac;
			// handle rollover, e.g. case 0.99 with prec 1 is 1.0
			if (frac >= pow10[prec])
			{
				frac = 0;
				++whole;
			}
		}
		else if (diff < 0.5)
		{
		}
		else if ((frac == 0) || (frac & 1))
		{
			// if halfway, round up if odd OR if last digit is 0
			++frac;
		}

		if (prec == 0U)
		{
			diff = value - (double)whole;
			if ((!(diff < 0.5) || (diff > 0.5)) && ((int)whole & 1))
			{
				// exactly 0.5 and ODD, then round up
				// 1.5 -> 2, but 2.5 -> 2
				++whole;
			}
		}
		else
		{
			uint count = prec;
			// now do fractional part, as an unsigned number
			while (len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE)
			{
				--count;
				buf = StringFunctions.ChangeCharacter(buf, len++, (sbyte)(48 + (frac % 10)));
				if (!(frac /= 10))
				{
					break;
				}
			}
			// add extra 0s
			while ((len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U))
			{
				buf = StringFunctions.ChangeCharacter(buf, len++, '0');
			}
			if (len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE)
			{
				// add decimal
				buf = StringFunctions.ChangeCharacter(buf, len++, '.');
			}
		}

		// do whole part, number is reversed
		while (len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE)
		{
			buf = StringFunctions.ChangeCharacter(buf, len++, (sbyte)(48 + (whole % 10)));
			if (!(whole /= 10))
			{
				break;
			}
		}

		// pad leading zeros
		if (!(flags & (1U << 1U)) && (flags & (1U << 0U)))
		{
			if (width != 0 && (negative || (flags & ((1U << 2U) | (1U << 3U)))))
			{
				width--;
			}
			while ((len < width) && (len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE))
			{
				buf = StringFunctions.ChangeCharacter(buf, len++, '0');
			}
		}

		if (len < DefineConstants.PRINTF_FTOA_BUFFER_SIZE)
		{
			if (negative)
			{
				buf = StringFunctions.ChangeCharacter(buf, len++, '-');
			}
			else if (flags & (1 << 2))
			{
				buf = StringFunctions.ChangeCharacter(buf, len++, '+'); // ignore the space if the '+' exists
			}
			else if (flags & (1 << 3))
			{
				buf = StringFunctions.ChangeCharacter(buf, len++, ' ');
			}
		}

		return _out_rev(@out, ref buffer, idx, maxlen, buf, len, width, flags);
	}

	// internal vsnprintf
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: Pointer arithmetic is detected on the parameter 'format', so pointers on this parameter are left unchanged:
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: Pointer arithmetic is detected on the parameter 'va', so pointers on this parameter are left unchanged:
	internal static int my_vsnprintf(uc_engine uc, out_fct_type @out, sbyte* buffer, uint maxlen, sbyte * format, sbyte * va)
	{
		int flags;
		uint width;
		uint precision;
		uint n;
		int idx = 0;

		if (buffer == null)
		{
			// use null output function
			@out = null;
		}

		while (*format != 0)
		{
			// format specifier?  %[flags][width][.precision][length]
			if (*format != (sbyte)'%')
			{
				// no
				@out(*format, buffer, idx++, maxlen);
                format++;
                continue;
			}
			else
			{
                // yes, evaluate it
                format++;
            }

			// evaluate flags
			flags = 0;
			do
			{
				switch (*format)
				{
				case (sbyte)'0':
					flags |= (1 << 0);
					format++;
					n = 1U;
					break;
				case (sbyte)'-':
					flags |= (1 << 1);
					 format++;
					n = 1U;
					break;
				case (sbyte)'+':
					flags |= (1 << 2);
                        format++;
                        n = 1U;
					break;
				case (sbyte)' ':
					flags |= (1 << 3);
                        format++;
                        n = 1U;
					break;
				case (sbyte)'#':
					flags |= (1 << 4);
                        format++;
                        n = 1U;
					break;
				default:
					n = 0U;
					break;
				}
			} while (n != 0);

			// evaluate width field
			width = 0U;
			if (_is_digit(*format))
			{
				width = _atoi(format);
			}
			else if (*format == (sbyte)'*')
			{
				int w = (int)va;
				va += sizeof(int);
				if (w < 0)
				{
					flags |= (1U << 1U); // reverse padding
					width = (uint)-w;
				}
				else
				{
					width = (uint)w;
				}
				format = format.Substring(1);
			}

			// evaluate precision field
			precision = 0U;
			if (*format == (sbyte)'.')
			{
				flags |= (1U << 10U);
				format = format.Substring(1);
				if (_is_digit(*format))
				{
					precision = _atoi(format);
				}
				else if (*format == (sbyte)'*')
				{
					int prec = (int)va;
					va += sizeof(int);
					precision = (int)prec > 0 ? (uint)prec : 0U;
					format = format.Substring(1);
				}
			}

			// evaluate length field
			switch (*format)
			{
			case 'l':
				flags |= (1U << 8U);
				format = format.Substring(1);
				if (*format == (sbyte)'l')
				{
					flags |= (1U << 9U);
					format = format.Substring(1);
				}
				break;
			case 'h':
				flags |= (1U << 7U);
				format = format.Substring(1);
				if (*format == (sbyte)'h')
				{
					flags |= (1U << 6U);
					format = format.Substring(1);
				}
				break;
	#if PRINTF_SUPPORT_PTRDIFF_T
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case 't':
				flags |= (sizeof(ptrdiff_t) == sizeof(int) ? (1U << 8U) : (1U << 9U));
				format = format.Substring(1);
				break;
	#endif
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case 'j':
				flags |= (sizeof(long) == sizeof(int) ? (1U << 8U) : (1U << 9U));
				format = format.Substring(1);
				break;
			case 'z':
				flags |= (sizeof(int) == sizeof(int) ? (1U << 8U) : (1U << 9U));
				format = format.Substring(1);
				break;
			default:
				break;
			}

			// evaluate specifier
			switch (*format)
			{
			case 'd':
			case 'i':
			case 'u':
			case 'x':
			case 'X':
			case 'o':
			case 'b':
			{
				// set the base
				uint @base;
				if (*format == (sbyte)'x' || *format == (sbyte)'X')
				{
					@base = 16U;
				}
				else if (*format == (sbyte)'o')
				{
					@base = 8U;
				}
				else if (*format == (sbyte)'b')
				{
					@base = 2U;
				}
				else
				{
					@base = 10U;
					flags &= ~(1 << 4); // no hash for dec format
				}
				// uppercase
				if (*format == (sbyte)'X')
				{
					flags |= (1 << 5);
				}

				// no plus or space flag for u, x, X, o, b
				if ((*format != (sbyte)'i') && (*format != (sbyte)'d'))
				{
					flags &= ~((1 << 2) | (1 << 3));
				}

				// ignore '0' flag when precision is given
				if ((flags & (1 << 10)) != 0)
				{
					flags &= ~(1 << 0);
				}

				// convert the integer
				if ((*format == (sbyte)'i') || (*format == (sbyte)'d'))
				{
					// signed
					if ((flags & (1 << 9)) != 0)
					{
	#if PRINTF_SUPPORT_LONG_LONG
						long value = (long)va;
						va += sizeof(long);
						idx = (int)_ntoa_long_long(@out, ref buffer, idx, maxlen, (ulong)(value > 0 ? value : 0 - value), value < 0, @base, precision, width, flags);
	#endif
					}
					else if ((flags & (1 << 8))!=0)
					{
						int value = (int)va;
						va += sizeof(int);
						idx = (int)_ntoa_long(@out, ref buffer, idx, maxlen, (uint)(value > 0 ? value : 0 - value), value < 0, @base, precision, width, flags);
					}
					else
					{
						int value = 0;
						if ((flags & (1 << 6)) != 0)
						{
							 value = (int)va;
							 va += sizeof(int);
						}
						else
						{
							if ((flags & (1 << 7)) != 0)
							{
								value = (short)((int)va);
								va += sizeof(int);
							}
							else
							{
								value = (int)va;
								va += sizeof(int);
							}
						}

						idx = (int)_ntoa_long(@out, ref buffer, idx, maxlen, (uint)(value > 0 ? value : 0 - value), value < 0, @base, precision, width, flags);
					}
				}
				else
				{
					// unsigned
					if ((flags & (1 << 9)) != 0)
					{
	#if PRINTF_SUPPORT_LONG_LONG
						ulong value = (ulong)va;
						va += sizeof(ulong);
						idx = (int)_ntoa_long_long(@out, ref buffer, idx, maxlen, value, false, @base, precision, width, flags);
	#endif
					}
					else if ((flags & (1 << 8))!=0)
					{
						uint value = (uint)va;
						va += sizeof(uint);
						idx = (int)_ntoa_long(@out, ref buffer, idx, maxlen, value, false, @base, precision, width, flags);
					}
					else
					{
						uint value = 0;

						if ((flags & (1 << 6)) != 0)
						{
							uint v = (uint)va;
							va += sizeof(uint);
							value = (byte)v;
						}
						else
						{
							if ((flags & (1 << 7)) != 0)
							{
								uint v = (uint)va;
								va += sizeof(uint);
								value = (ushort)v;
							}
							else
							{
								value = (uint)va;
								va += sizeof(uint);
							}
						}
						idx = (int)_ntoa_long(@out, ref buffer, idx, maxlen, value, false, @base, precision, width, flags);
					}
				}
				format = format.Substring(1);
				break;
			}
	#if PRINTF_SUPPORT_FLOAT
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case 'f':
			case 'F':
			{
				if (*format == (sbyte)'F')
				{
					flags |= (1 << 5);
				}
				double value = (double)va;
				va += sizeof(double);
				idx = (int)_ftoa(@out, ref buffer, idx, maxlen, value, precision, width, flags);
				format = format.Substring(1);
				break;
			}
	#if PRINTF_SUPPORT_EXPONENTIAL
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case 'e':
			case 'E':
			case 'g':
			case 'G':
				if ((*format == (sbyte)'g') || (*format == (sbyte)'G'))
				{
					flags |= (1U << 11U);
				}
				if ((*format == (sbyte)'E') || (*format == (sbyte)'G'))
				{
					flags |= (1U << 5U);
				}
				idx = _etoa(@out, buffer, idx, maxlen, my_va_arg(va, double), precision, width, flags);
				format = format.Substring(1);
				break;
	#endif
	#endif
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case 'c':
			{
				uint l = 1U;
				int value = 0;
				// pre padding
				if (((flags & (1 << 1)) == 0))
				{
					while (l++ < width)
					{
						@out(' ', buffer, idx++, maxlen);
					}
				}
				// char output
				value = (int)va;
				va += sizeof(int);
				@out((sbyte)value, buffer, idx++, maxlen);
				// post padding
				if ((flags & (1 << 1)) != 0)
				{
					while (l++ < width)
					{
						@out(' ', buffer, idx++, maxlen);
					}
				}
				format = format.Substring(1);
				break;
			}

			case 's':
			{
				uint value = 0;
				value = (uint)va;
				va += sizeof(uint);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
sbyte* p = (sbyte*)toHostPtr(value);
				//sbyte p = (string)toHostPtr(value);
				uint l = _strnlen_s(p, (uint)(precision != 0 ? precision : uint.MaxValue));
				// pre padding
				if ((flags & (1 << 10)) != 0)
				{
					l = (l < precision != 0 ? l : precision);
				}
				if (((flags & (1 << 1)) == 0))
				{
					while (l++ < width)
					{
						@out(' ', buffer, idx++, maxlen);
					}
				}
				// string output
				while ((p != 0) && (!(flags & (1U << 10U)) || precision--))
				{
					@out(*(p++), buffer, idx++, maxlen);
				}
				// post padding
				if ((flags & (1U << 1U)) != 0)
				{
					while (l++ < width)
					{
						@out(' ', buffer, idx++, maxlen);
					}
				}
				format = format.Substring(1);
				break;
			}

			case 'p':
			{
				bool is_ll;
				width = sizeof(object) * 2U;
				flags |= (1U << 0U) | (1U << 5U);
	#if PRINTF_SUPPORT_LONG_LONG
				is_ll = sizeof(long);
				if (is_ll)
				{
					uint value = (uint)va;
					va += sizeof(uint);
					idx = (int)_ntoa_long_long(@out, ref buffer, idx, maxlen, value, false, 16U, precision, width, flags);
				}
				else
				{
	#endif
					uint value = (uint)va;
					va += sizeof(uint);
					idx = (int)_ntoa_long(@out, ref buffer, idx, maxlen, (uint)value, false, 16U, precision, width, flags);
	#if PRINTF_SUPPORT_LONG_LONG
				}
	#endif
				format = format.Substring(1);
				break;
			}

			case '%':
				@out('%', buffer, idx++, maxlen);
				format = format.Substring(1);
				break;

			default:
				@out(*format, buffer, idx++, maxlen);
				format = format.Substring(1);
				break;
			}
		}

		// termination
		@out((sbyte)0, buffer, idx < maxlen != 0 ? idx : maxlen - 1U, maxlen);

		// return written chars without terminating \0
		return (int)idx;
	}



	// The following come from joyrider and from disassembly.
	public static uint waveout_open(waveout_args* args)
	{
		//Console.Write("args channel {0:D} format {1:D} sample_rate {2:D} volume {3:D}, channel {4:D}\n", args.channel, args.format, args.sample_rate, args.volume, args.channel);

		pthread_t tid = new pthread_t();
		int ret = pthread_create(tid, null, MixerThreadRun, args);
		if (ret != 0)
		{
			Console.Write("pthread_create dingooRun failed\n");
			Debug.Assert(0);
		}

		return 1;
	}

    private static int pthread_create(pthread_t tid, object p, Func<object, object> mixerThreadRun, waveout_args* args)
    {
        throw new NotImplementedException();
    }

    public static uint waveout_write(uint inst, byte* buffer, uint count)
	{
		return MixerWriteBuff( buffer, count);
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//uint waveout_close(uint inst);
	public static uint waveout_can_write()
	{
		return MixerPlaying();
	}
	public static uint waveout_set_volume(uint vol)
	{
		MixerSetVolume(vol);
		return 1;
	}


	// 字节对齐
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//int wstrlen(ref string txt);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//void cpsrToStr(uint v, ref string @out);
	public static string memTypeStr(uc_mem_type type)
	{
		// clang-format off
		switch (type)
		{
		case uc_mem_type.UC_MEM_READ:
			return "UC_MEM_READ";
		case uc_mem_type.UC_MEM_WRITE:
			return "UC_MEM_WRITE";
		case uc_mem_type.UC_MEM_FETCH:
			return "UC_MEM_FETCH";
		case uc_mem_type.UC_MEM_READ_UNMAPPED:
			return "UC_MEM_READ_UNMAPPED";
		case uc_mem_type.UC_MEM_WRITE_UNMAPPED:
			return "UC_MEM_WRITE_UNMAPPED";
		case uc_mem_type.UC_MEM_FETCH_UNMAPPED:
			return "UC_MEM_FETCH_UNMAPPED";
		case uc_mem_type.UC_MEM_WRITE_PROT:
			return "UC_MEM_WRITE_PROT";
		case uc_mem_type.UC_MEM_READ_PROT:
			return "UC_MEM_READ_PROT";
		case uc_mem_type.UC_MEM_FETCH_PROT:
			return "UC_MEM_FETCH_PROT";
		case uc_mem_type.UC_MEM_READ_AFTER:
			return "UC_MEM_READ_AFTER";
		}
		// clang-format on
		return "<error type>";
	}
	public static void dumpREG(uc_engine uc)
	{
        FILE stdout = null;
        dumpREG2File(uc, stdout);
	}
	public static void dumpStackCall(uc_engine uc, uint stack_start_address)
	{
		uint v;
		Console.Write("==========================STACK=================================\n");
		uc_reg_read(uc, UC_MIPS_REG_SP,out v);
		Console.Write("0x{0:x8}:\t", v);
		void* stack = toHostPtr(v);
		int i = 0;
		for (int j = 0; j < stack_start_address - v; j += 4)
		{
			Console.Write("{0:x8} ", ((uint*)stack)[++i]);
			if (j % 16 == 0)
			{
				Console.Write("\n");
				Console.Write("0x{0:x8}:\t", v + j);
			}
		}
		Console.Write("\n");

		Console.Write("==============================================================\n");
	}
	public static void dumpAsm(uc_engine uc)
	{
		uint ra;
		uint address = 0;
		Console.Write("==========================DISASM==============================\n");
		uc_reg_read(uc, UC_MIPS_REG_RA,out ra);

		address = ra - 256;
		while ((ra + 4) != address)
		{
			dumpDisasm(uc, address);
			address += 4;
		}

		Console.Write("==============================================================\n");
	}
	public static void dumpREG2File(uc_engine uc, FILE fp)
	{
		uint v;

		fprintf(fp, "==========================REG=================================\n");
		//uc_reg_read(uc, UC_MIPS_REG_ZERO, &v); printf("ZERO=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_AT, out v);
		fprintf(fp, "AT=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_V0, out v);
		fprintf(fp, "V0=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_V1, out v);
		fprintf(fp, "V1=%08X\t\n", v);

		uc_reg_read(uc, UC_MIPS_REG_A0, out v);
		fprintf(fp, "A0=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_A1, out v);
		fprintf(fp, "A1=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_A2, out v);
		fprintf(fp, "A2=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_A3, out v);
		fprintf(fp, "A3=%08X\t\n", v);

		uc_reg_read(uc, UC_MIPS_REG_S0, out v);
		fprintf(fp, "S0=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S1, out v);
		fprintf(fp, "S1=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S2, out v);
		fprintf(fp, "S2=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S3, out v);
		fprintf(fp, "S3=%08X\t\n", v);
		uc_reg_read(uc, UC_MIPS_REG_S4, out v);
		fprintf(fp, "S4=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S5, out v);
		fprintf(fp, "S5=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S6, out v);
		fprintf(fp, "S6=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_S7, out v);
		fprintf(fp, "S7=%08X\t\n", v);

		uc_reg_read(uc, UC_MIPS_REG_LO, out v);
		fprintf(fp, "LO=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_HI, out v);
		fprintf(fp, "HI=%08X\t\n", v);

		uc_reg_read(uc, UC_MIPS_REG_PC,out v);
		fprintf(fp, "PC=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_SP, out v);
		fprintf(fp, "SP=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_FP, out v);
		fprintf(fp, "FP=%08X\t", v);
		uc_reg_read(uc, UC_MIPS_REG_RA, out v);
		fprintf(fp, "RA=%08X\t\n", v);
		fprintf(fp, "==============================================================\n");
	}

    



    //C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
    //void dumpMemStr(object ptr, uint len);
    public static void dumpMem(object buffer, uint count)
	{
		//byte[] d = (byte)buffer;
		//for (int i = 0; i < count; ++i)
		//{
		//	Console.Write("{0:x2} ", d[(int)i]);
		//	if ((i + 1) % 16 == 0)
		//	{
		//		Console.Write("\n");
		//	}
		//}

		//Console.Write("\n");
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//string getSplitStr(ref string str, sbyte split, int n);

	public static void toHexString(void* buff, uint count, sbyte* @out)
	{
		int i = 0;
		for (; i < count; i++)
		{
			//@out = @out.Substring(0, 3 * i) + string.Format("{0:x2} ", ((byte*)buff)[(int)i]);
		}
	}


//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//uint copyWstrToMrp(ref string str);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//uint copyStrToMrp(ref string str);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//void printScreen(ref string filename, ref ushort buf);

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//long get_uptime_ms();
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The implementation of the following method could not be found:
	//long get_time_ms();

//wstring=>string

	//wstring=>string
	public static string WString2String(string ws)
	{
		string strLocale = setlocale(LC_ALL, "");
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: const char* wchSrc = ws.c_str();
		char wchSrc = ws;
		uint nDestSize = wcstombs(null, wchSrc, 0) + 1;
		string chDest = new string(new char[nDestSize - 1]);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		memset(chDest, 0, nDestSize);
		wcstombs(chDest, wchSrc, nDestSize);
		string strResult = ((char)chDest).ToString();
		chDest = null;
		setlocale(LC_ALL, strLocale);
		return strResult;
	}
// string => wstring

	// string => wstring
	public static string String2WString(string s)
	{
		string strLocale = setlocale(LC_ALL, "");
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: const sbyte* chSrc = s.c_str();
		sbyte chSrc = s;
		uint nDestSize = mbstowcs(null, chSrc, 0) + 1;
		char[] wchDest = new char[nDestSize];
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'wmemset' has no equivalent in C#:
		wmemset(wchDest, 0, nDestSize);
		mbstowcs(wchDest, chSrc, nDestSize);
		string wstrResult = wchDest;
		wchDest = null;
		setlocale(LC_ALL, strLocale);
		return wstrResult;
	}

	internal static void dumpDisasm(uc_engine uc, uint address)
	{
		cs_insn insn;
		uint binary;
		uint count;
		csh handle = new csh();
		uint size = 4;

		if (cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32, handle) != CS_ERR_OK)
		{
			Console.Write("debug cs_open() fail.");
			Environment.Exit(1);
		}
		uc_mem_read(uc, address, binary, size);
		count = cs_disasm(handle, (byte) & binary, size, address, 1, insn);
		if (count > 0)
		{
			for (int j = 0; j < count; j++)
			{
				Console.Write("{0:X8}:    {1:x8}    {2}\t{3}\n", address, binary, insn[(int)j].mnemonic, insn[(int)j].op_str);
			}
		}
		else
		{
			Console.Write("{0:X8}:    {1:x8}  -----------disasm-error----------- \n", address, binary);
		}

		cs_close(handle);
	}


	public static uint fsys_fopen(string name, string mode)
	{
		uint index = 0;
		FILE fp = null;
		if (name == null || mode == null)
		{
			return 0;
		}
		fp = fopen(name, mode);
		if (fp == null)
		{
			return 0;
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: for (index = 1; index < sizeof(s_FILE_Map) / sizeof(s_FILE_Map[0]); ++index)
		for (index = 1; index < s_FILE_Map.Length; ++index)
		{
			if (s_FILE_Map[index] == null)
			{
				break;
			}
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 WARNING: This 'sizeof' ratio was replaced with a direct reference to the array length:
//ORIGINAL LINE: if (index >= sizeof(s_FILE_Map) / sizeof(s_FILE_Map[0]))
		if (index >= s_FILE_Map.Length)
		{
			Console.Write("Failed s_FILE_Map with error : {0:D}, index {1:D} \n", errno, index);
			Debug.Assert(0);
		}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: s_FILE_Map[index] = fp;
		s_FILE_Map[index] = fp;

		return index;
	}

   

    //int fread(void* ptr, size_t size, size_t count, FILE* stream);
    public static uint vm_fread(void* ptr, uint size, uint count, uint stream)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return (uint)fread(ptr, size, count, fp);
	}
	public static uint fsys_fclose(uint stream)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return fclose(fp);
	}

// int fseek(FILE* stream, long int offset, int origin);
	public static uint fsys_fseek(uint stream, uint offset, uint origin)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return fseek(fp, offset, origin);
	}
	public static uint fsys_ftell(uint stream)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return ftell(fp);
	}
	public static uint fsys_fwrite(void* ptr, uint size, uint count, uint stream)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return (uint)fwrite(ptr, size, count, fp);
	}
	public static uint fsys_feof(uint stream)
	{
		if (stream <= 0)
		{
			return 0;
		}

		FILE fp = s_FILE_Map[stream];
		return (uint)feof(fp);
	}



	public static FILE[] s_FILE_Map = {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null};

	public static int InitVmMem(uc_engine uc, app _app)
	{
		uc_err err = new uc_err();

		if (VM_APP_BEGIN_ADDRESS != _app.origin)
		{
			Console.Write("InitVmMem invalid origin 0x{0:x8} \n", _app.origin);
			return -1;
		}

		s_App_Prog_Ptr = _app.bin_data;
		s_App_Prog_Size = _app.bin_size;

		s_Heap_Begin_Address = ((((_app.prog_size + _app.origin)) + ((4096) - 1)) & ~((4096) - 1));

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		memset(s_HeapMemPtr, 0x00, VM_HEAP_SIZE);
		initMemoryManager(s_HeapMemPtr, VM_HEAP_SIZE);

		err = uc_mem_map_ptr(uc, s_Heap_Begin_Address, VM_HEAP_SIZE, UC_PROT_ALL, s_HeapMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_HeapMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}


//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		memset(s_StackMemPtr, 0x00, VM_STACK_SIZE);
		err = uc_mem_map_ptr(uc, VM_STACK_UPPER_ADDRESS - VM_STACK_SIZE, VM_STACK_SIZE, UC_PROT_ALL, s_StackMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_StackMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		uint value = VM_STACK_UPPER_ADDRESS;
		uc_reg_write(uc, UC_MIPS_REG_SP, value);


		//Register
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memset' has no equivalent in C#:
		memset(s_RegisterMemPtr, 0x00, CPU_REGISTER_SIZE);
		err = uc_mem_map_ptr(uc, CPU_REGISTER_BASE_ADDR - CPU_REGISTER_SIZE, CPU_REGISTER_SIZE, UC_PROT_ALL, s_RegisterMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_RegisterMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		return 0;
	}

	public static int InitVmMemSubTask(uc_engine uc)
	{
		uc_err err = new uc_err();

		err = uc_mem_map_ptr(uc, s_Heap_Begin_Address, VM_HEAP_SIZE, UC_PROT_ALL, s_HeapMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_HeapMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		err = uc_mem_map_ptr(uc, VM_STACK_UPPER_ADDRESS - VM_STACK_SIZE, VM_STACK_SIZE, UC_PROT_ALL, s_StackMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_StackMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		//Register
		err = uc_mem_map_ptr(uc, CPU_REGISTER_BASE_ADDR - CPU_REGISTER_SIZE, CPU_REGISTER_SIZE, UC_PROT_ALL, s_RegisterMemPtr);
		if (err != null)
		{
			Console.Write("Failed mem map s_RegisterMemPtr: {0:D} ({1})\n", err, uc_strerror(err));
			return -1;
		}

		return 0;
	}

	public static uint vm_malloc(uint len)
	{
		//printf("malloc(len = %d) = ", len);
		object p = my_mallocExt(len);
		if (p == null)
		{
			return null;
		}
		uint ret = (uint)(((uint)p - (uint)s_HeapMemPtr) + s_Heap_Begin_Address);
		//printf("%08x \n", ret);
		return ret;
	}
	public static void vm_free(uint addr)
	{
		//printf("free(addr = %08x) \n", addr);
		object p = (object)((uint)addr - (uint)s_Heap_Begin_Address + (uint)s_HeapMemPtr);
		my_freeExt((object)p);
	}
	public static uint vm_realloc(uint addr, uint len)
	{
		object p = (object)((uint)addr - (uint)s_Heap_Begin_Address + (uint)s_HeapMemPtr);
		object retPtr = my_reallocExt((object)p, len);
		return (uint)(((uint)retPtr - (uint)s_HeapMemPtr) + s_Heap_Begin_Address);
	}

	public static void* toHostPtr(uint addr)
	{
		//heap
		if (addr >= s_Heap_Begin_Address && addr < s_Heap_Begin_Address + VM_HEAP_SIZE)
		{
            void* p = (void*)((uint)addr - (uint)s_Heap_Begin_Address + (uint)s_HeapMemPtr);
			return p;
		}

		//stack
		if (addr <= VM_STACK_UPPER_ADDRESS  && addr > VM_STACK_UPPER_ADDRESS - VM_STACK_SIZE)
		{
			object p = (object)((uint)addr - (uint)(VM_STACK_UPPER_ADDRESS - VM_STACK_SIZE) + (uint)s_StackMemPtr);
			return p;
		}

		//code
		if (addr >= VM_APP_BEGIN_ADDRESS  && addr < VM_APP_BEGIN_ADDRESS + s_App_Prog_Size)
		{
			object p = (object)((uint)addr - (uint)VM_APP_BEGIN_ADDRESS + (uint)s_App_Prog_Ptr);
			return p;
		}
		//framebuffer
		if (addr >= VM_LCD_FB_ADDRESS && addr < VM_LCD_FB_ADDRESS + DefineConstants.VM_LCD_FB_SIZE)
		{
			object p = (object)((uint)addr - (uint)VM_LCD_FB_ADDRESS + (uint)s_LcdFrameBufferPtr);
			return p;
		}

		Console.Write("ERR: toHostPtr 0x{0:x8}\n", addr);
		return null;
	}
	public static uint toVmPtr(object ptr)
	{
		//heap
		if ((uint)ptr >= (uint)s_HeapMemPtr && (uint)ptr < (uint)s_HeapMemPtr + VM_HEAP_SIZE)
		{
			return (uint)(((uint)ptr - (uint)s_HeapMemPtr) + s_Heap_Begin_Address);
		}

		//stack
		if ((uint)ptr >= (uint)s_StackMemPtr && (uint)ptr > (uint)ptr + VM_STACK_SIZE)
		{
			return (uint)(((uint)ptr - (uint)s_StackMemPtr) + (VM_STACK_UPPER_ADDRESS - VM_STACK_SIZE));
		}

		//code
		if ((uint)ptr >= VM_APP_BEGIN_ADDRESS && (uint)ptr > VM_APP_BEGIN_ADDRESS + s_App_Prog_Size)
		{
			return (uint)(((uint)ptr - (uint)s_App_Prog_Ptr) + VM_APP_BEGIN_ADDRESS);
		}
		//framebuffer
		if ((uint)ptr >= VM_LCD_FB_ADDRESS && (uint)ptr > VM_LCD_FB_ADDRESS + DefineConstants.VM_LCD_FB_SIZE)
		{
			return (uint)(((uint)ptr - (uint)s_LcdFrameBufferPtr) + VM_LCD_FB_ADDRESS);
		}
		Console.Write("ERR: toVmPtr 0x{0:x}\n", ptr);
		return 0;
	}

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)
	// JZ4740оƬ�����ַӳ���ϵ jz4740_03_emc_spec.pdf 
	//Figure 1-1 Physical Address Space Map
	//Table 1 - 2 Physical Address Space Map
	//|Start Address | End Address  |Connectable Memory  |Capacity
	//|H��0000 0000  | H��07FF FFFF |SDRAM space         |128 MB
	//|H��0800 0000  | H��0FFF FFFF |Static memory space |128 MB
	//|H��1000 0000  | H��13FF FFFF |Internal I / O space|64 MB
	//|H��1400 0000  | H��1BFF FFFF |Static memory space |128MB
	//|H��1C00 0000  | H��1FBF FFFF |Un - used           |60MB
	//|H��1FC0 0000  | H��1FC0 0FFF |On - chip boot ROM  |4KB
	//|H��1FC0 1000  | H��1FFF FFFF |Un - used           |4095KB
	//|H��2000 0000  | H��BFFF FFFF |SDRAM space         |2944 MB
	//|H��D000 0000  | H��FFFF FFFF |Reserved space      |512 MB



	//ϵͳ�������ڴ����ӳ��
	//|----------------|--------------------------|----------------------|-------------------------------------|
	//|0x8000_0000     |0x80a0_0000               |                      |             |                       |0xFFFF_FFFF
	//|��ʼ��ַ        |app�����ַ               |                      |             |
	//                 |����� |  ���ݶ� |  bss   |   ��    |    |  ջ   |             |
	//                                            |  16MB   |    |  8MB  |0xa000_0000  |                        |ӳ���ڴ����С��0xc000_0000
	//                                                         |LCD_FB 0x9000_0000     |
	//                                                                                 |CPU�Ĵ�����ַ0xb000_0000
	public const uint CPU_REGISTER_BASE_ADDR = 0xB0000000;
	public const uint CPU_REGISTER_SIZE = 0x04000000;
	public const uint VM_HEAP_SIZE = 64 * 1024 * 1024;
	public const uint VM_STACK_SIZE = 16 * 1024 * 1024;
	public const uint VM_STACK_UPPER_ADDRESS = 0xA0000000;
	public const uint VM_APP_BEGIN_ADDRESS = 0x80a00000;
	public static object s_App_Prog_Ptr = 0;
	public static uint s_App_Prog_Size = 0;
	public static uint s_Heap_Begin_Address = 0;

    //�̶������ڴ�
    public static byte* s_HeapMemPtr;
    public static byte* s_StackMemPtr;

    public static byte* s_RegisterMemPtr;

	public static uint LG_mem_min; // ��δ������ĳ��ȣ�
	public static uint LG_mem_top; // ��̬���뵽�������ڴ�ֵ
	public static LG_mem_free_t LG_mem_free = new LG_mem_free_t();
	public static object LG_mem_base;
	public static uint LG_mem_len;
	public static object Origin_LG_mem_base;
	public static uint Origin_LG_mem_len;
	public static object LG_mem_end;
	public static uint LG_mem_left; // ʣ���ڴ�

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define realLGmemSize(x) (((x) + 7) & (0xfffffff8))


	public static void initMemoryManager(object baseAddress, uint len)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf("initMemoryManager: baseAddress:0x%" PRIx64 " len: 0x%08x\n", (uint)baseAddress, len);
		//Console.Write("initMemoryManager: baseAddress:0x%" PRIx64 " len: 0x{1:x8}\n", (uint)baseAddress, len);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: Origin_LG_mem_base = baseAddress;
		Origin_LG_mem_base = baseAddress;
		Origin_LG_mem_len = len;

		LG_mem_base = (object)((uint)((uint)Origin_LG_mem_base + 3) & (~3));
		LG_mem_len = (Origin_LG_mem_len - ((uint)LG_mem_base - (uint)Origin_LG_mem_base)) & (~3);
		LG_mem_end = (object)((uint)LG_mem_base + LG_mem_len);
		LG_mem_free.next = 0;
		LG_mem_free.len = 0;
		((LG_mem_free_t)LG_mem_base).next = LG_mem_len;
		((LG_mem_free_t)LG_mem_base).len = LG_mem_len;
		LG_mem_left = LG_mem_len;
	#if MEM_DEBUG
		LG_mem_min = LG_mem_len;
		LG_mem_top = 0;
	#endif
	}
	public static void printMemoryInfo()
	{
		Console.Write(".......total:{0:D}, min:{1:D}, free:{2:D}, top:{3:D}\n", LG_mem_len, LG_mem_min, LG_mem_left, LG_mem_top);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf(".......base:%p, end:%p\n", LG_mem_base, LG_mem_end);
		Console.Write(".......base:%p, end:%p\n", LG_mem_base, LG_mem_end);
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf(".......obase:%p, olen:%d\n", Origin_LG_mem_base, Origin_LG_mem_len);
		Console.Write(".......obase:%p, olen:{1:D}\n", Origin_LG_mem_base, Origin_LG_mem_len);
	}

	public static object my_malloc(uint len)
	{
		LG_mem_free_t previous;
		LG_mem_free_t nextfree;
		LG_mem_free_t l;
		object ret;

		len = (uint)(((len) + 7) & (0xfffffff8));
		if (len >= LG_mem_left)
		{
			Console.Write("my_malloc no memory: len {0:x8}\n", len);
			goto err;
		}
		if (len == 0)
		{
			Console.Write("my_malloc invalid memory request");
			goto err;
		}
		if ((uint)LG_mem_base + LG_mem_free.next > (uint)LG_mem_end)
		{
			Console.Write("my_malloc corrupted memory");
			goto err;
		}
		previous = LG_mem_free;
		nextfree = (LG_mem_free_t)((uint)LG_mem_base + previous.next);
		while ((string)nextfree < LG_mem_end)
		{
			if (nextfree.len == len)
			{
				previous.next = nextfree.next;
				LG_mem_left -= len;
	#if MEM_DEBUG
				if (LG_mem_left < LG_mem_min)
				{
					LG_mem_min = LG_mem_left;
				}
				if (LG_mem_top < previous.next)
				{
					LG_mem_top = previous.next;
				}
	#endif
				ret = (object)nextfree;
				goto end;
			}
			if (nextfree.len > len)
			{
				l = (LG_mem_free_t)((string)nextfree + len);
				l.next = nextfree.next;
				l.len = (uint)(nextfree.len - len);
				previous.next += len;
				LG_mem_left -= len;
	#if MEM_DEBUG
				if (LG_mem_left < LG_mem_min)
				{
					LG_mem_min = LG_mem_left;
				}
				if (LG_mem_top < previous.next)
				{
					LG_mem_top = previous.next;
				}
	#endif
				ret = (object)nextfree;
				goto end;
			}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: previous = nextfree;
			previous = nextfree;
			nextfree = (LG_mem_free_t)((uint)LG_mem_base + nextfree.next);
		}
		Console.Write("my_malloc no memory: len {0:x8}\n", len);
	err:
		return 0;
	end:
		return ret;
	}

	public static void my_free(object p, uint len)
	{
		LG_mem_free_t free;
		LG_mem_free_t n;
		len = (uint)(((len) + 7) & (0xfffffff8));
	#if MEM_DEBUG
		if (len == 0 || p == null || (string)p < LG_mem_base || (string)p >= LG_mem_end != null || (string)p + len > LG_mem_end || (string)p + len <= LG_mem_base)
		{
			Console.Write("my_free invalid\n");
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf("p=%" PRIXPTR ", l=%d, base=%" PRIXPTR ",LG_mem_end=%" PRIXPTR "\n", (uint)p, len, (uint)LG_mem_base, (uint)LG_mem_end);
			//Console.Write("p=%" PRIXPTR ", l={1:D}, base=%" PRIXPTR ",LG_mem_end=%" PRIXPTR "\n", (uint)p, len, (uint)LG_mem_base, (uint)LG_mem_end);
			return;
		}
	#endif
		free = LG_mem_free;
		n = (LG_mem_free_t)((uint)LG_mem_base + free.next);
		while (((string)n < LG_mem_end) && ((object)n < p))
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to variables (in C#, the variable no longer points to the original when the original variable is re-assigned):
//ORIGINAL LINE: free = n;
			free = n;
			n = (LG_mem_free_t)((uint)LG_mem_base + n.next);
		}
	#if MEM_DEBUG
		if (p == (object)free || p == (object)n)
		{
			Console.Write("my_free:already free\n");
			return;
		}
	#endif
		if ((free != LG_mem_free) && ((string)free + free.len == p))
		{
			free.len += len;
		}
		else
		{
			free.next = (uint)((string)p - LG_mem_base);
			free = (LG_mem_free_t)p;
			free.next = (uint)((string)n - LG_mem_base);
			free.len = len;
		}
		if (((string)n < LG_mem_end) && ((string)p + len == (string)n))
		{
			free.next = n.next;
			free.len += n.len;
		}
		LG_mem_left += len;
	}

	public static object my_realloc(object p, uint oldlen, uint len)
	{
		uint minsize = (oldlen > len) ? len : oldlen;
		object newblock;
		if (p == null)
		{
			return my_malloc(len);
		}
		if (len == 0)
		{
			my_free(p, oldlen);
			return null;
		}
		newblock = my_malloc(len);
		if (newblock == null)
		{
			return newblock;
		}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memmove' has no equivalent in C#:
		memmove(newblock, p, minsize);
		my_free(p, oldlen);
		return newblock;
	}

	public static object my_mallocExt(uint len)
	{
		object p = null;
		if (len == 0)
		{
			return null;
		}
		p = my_malloc(len + sizeof(uint));
		if (p != null)
		{
			((uint)p)[0] = len;
			return (object)((uint)p + 1);
		}
		return p;
	}
	public static void my_freeExt(object p)
	{
		if (p != null)
		{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: C# does not have an equivalent to pointers to value types:
//ORIGINAL LINE: uint* t = (uint*)p - 1;
			uint t = (uint)p - 1;
			my_free(t, t + sizeof(uint));
		}
	}

	public static object my_reallocExt(object p, uint newLen)
	{
		if (p == null)
		{
			return my_mallocExt(newLen);
		}
		else if (newLen == 0)
		{
			my_freeExt(p);
			return null;
		}
		else
		{
			uint oldlen = (uint)p - 1 + sizeof(uint);
			uint minsize = (oldlen < newLen) ? oldlen : newLen;
			object newblock = my_mallocExt(newLen);
			if (newblock == null)
			{
				return newblock;
			}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'memmove' has no equivalent in C#:
			memmove(newblock, p, minsize);
			my_freeExt(p);
			return newblock;
		}
	}

	//framebuffer
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern uint VM_LCD_FB_ADDRESS;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern byte s_LcdFrameBufferPtr[DefineConstants.VM_LCD_FB_SIZE];

	////typedef unsigned int OS_STK;
	////uint8_t OSTaskCreate(void (*task)(void* data), void* data, OS_STK* stack, uint8_t priority);
	public static uint OSTaskCreate(uint taskFuncAddr, uint dataPtr, uint stackPtr, uint priority)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The memory management function 'malloc' has no equivalent in C#:
		TaskStruct taskStruct = (TaskStruct)malloc(sizeof(TaskStruct));
		if (taskStruct == null)
		{
			Console.Write("OSTaskCreate malloc failed\n");
			return -1;
		}
		taskStruct.dataPtr = dataPtr;
		taskStruct.taskFuncAddr = taskFuncAddr;
		taskStruct.stackPtr = stackPtr;
		taskStruct.priority = priority;

		int ret = pthread_create(taskStruct.tid, null, subTaskRun, taskStruct);
		if (ret != 0)
		{
			Console.Write("pthread_create dingooRun failed\n");
			Debug.Assert(0);
		}

		return DefineConstants.OS_NO_ERR;
	}

	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
	//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern uint s_AppDataAddr;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern uint s_AppDataBuffSize;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern object* s_AppDataBuff;
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: 'extern' variable declarations are not required in C#:
	//extern app* s_app;

//	internal static bool hook_mem_invalid(uc_engine uc, uc_mem_type type, ulong address, int size, long value, object user_data)
//	{
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
////ORIGINAL LINE: printf(">>> Tracing mem_invalid mem_type:%s at 0x%" PRIx64 ", size:0x%x, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
//		//Console.Write(">>> Tracing mem_invalid mem_type:{0} at 0x%" PRIx64 ", size:0x{2:x}, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
//		dumpREG(uc);
//		dumpAsm(uc);
//		return false;
//	}


	internal static void hook_mem_valid(uc_engine uc, uc_mem_type type, ulong address, int size, long value, object user_data)
	{
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
//ORIGINAL LINE: printf(">>> Tracing mem_valid mem_type:%s at 0x%" PRIx64 ", size:0x%x, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		//Console.Write(">>> Tracing mem_valid mem_type:{0} at 0x%" PRIx64 ", size:0x{2:x}, value:0x%" PRIx64 "\n", memTypeStr(type), address, size, value);
		if (type == uc_mem_type.UC_MEM_READ && size <= 4)
		{
			uint v;
			uint pc;
			uc_mem_read(uc,(uint) address,out v, size);
			uc_reg_read(uc, UC_MIPS_REG_PC, out pc);
			Console.Write("PC:0x{0:X},read:0x{1:X}\n", pc, v);
		}
	}
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This was formerly a static local variable declaration (not allowed in C#):
//private static int hook_code_debug_print_flag = 1;

//	internal static void hook_code_debug(uc_engine uc, ulong address, uint size, object user_data)
//	{
//		string str = new string(new char[60]);
//		string ptr;
//		int eqPos;
//		uc_err err = new uc_err();
//		uint stack_start_address = (uint)user_data;

//		cs_mode mode = new cs_mode();
//		uint pc;
//		uc_reg_read(uc, UC_MIPS_REG_PC, pc);

//		if (size <= 4)
//		{
//			cs_insn insn;
//			uint binary;
//			uint count;
//			csh handle = new csh();
//			uint cpsr;

//			if (cs_open(CS_ARCH_MIPS, CS_MODE_MIPS32, handle) != CS_ERR_OK)
//			{
//				Console.Write("debug cs_open() fail.");
//				Environment.Exit(1);
//			}
//			uc_mem_read(uc, address,out binary, size);
//			count = cs_disasm(handle, (byte) & binary, size, address, 1, insn);
//			if (count > 0)
//			{
//				for (uint j = 0; j < count; j++)
//				{
//	//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: This static local variable declaration (not allowed in C#) has been moved just prior to the method:
//	//				static int print_flag = 1;
//					if (hook_code_debug_print_flag)
//					{
//						Console.Write("{0:X8}:    {1:x8}    {2}\t{3}\n", pc, binary, insn[j].mnemonic, insn[j].op_str);
//						//dumpREG(uc);
//						//dumpStackCall(uc, stack_start_address);
//					}
//				}
//				cs_free(insn, count);
//			}
//			else
//			{
////C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following line has a C format specifier which cannot be directly translated to C#:
////ORIGINAL LINE: printf("%08X:     %08x    0x%" PRIXPTR "    %d]> ", pc, binary, address, size);
//				//Console.Write("{0:X8}:     {1:x8}    0x%" PRIXPTR "    {3:D}]> ", pc, binary, address, size);
//			}
//			cs_close(handle);
//		}
//	}
    public static int PRIXPTR;

    public static object subTaskRun(object data)
	{
		TaskStruct taskStruct = (TaskStruct)data;

		uint entry = taskStruct.taskFuncAddr;

		uc_engine uc;
		uc_err err = new uc_err();
		uc_hook trace = new uc_hook();

		Console.Write("subTaskRun start:entry 0x{0:x8}, priority {1:D}\n", entry, taskStruct.priority);

		err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, uc);
		if (err != null)
		{
			Console.Write("Failed on uc_open() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			return null;
		}

		//�ڴ��ʼ��
		err = uc_mem_map_ptr(uc, s_AppDataAddr, s_AppDataBuffSize, UC_PROT_ALL, s_AppDataBuff);
		if (err != null)
		{
			Console.Write("Failed mem map: {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		if (InitVmMemSubTask(uc) != 0)
		{
			Console.Write("Failed on InitVmMemSubTask\n");
			Environment.Exit(1);
		}

		if (InitFb(uc) != 0)
		{
			Console.Write("Failed on InitFb\n");
			Environment.Exit(1);
		}

		// ��ʼ��bridge
		err = bridge_init(uc, s_app);
		if (err != null)
		{
			Console.Write("Failed bridge_init(): {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		//uc_hook_add(uc, &trace, UC_HOOK_CODE, hook_code_debug, (void*)&(taskStruct->stackPtr), 1, 0);
		//uc_hook_add(uc, &trace, UC_HOOK_MEM_INVALID, hook_mem_invalid, NULL, 1, 0, 0);
		//uc_hook_add(uc, &trace, UC_HOOK_MEM_VALID, hook_mem_valid, NULL, 1, 0, 0);

		//��ʼ���Ĵ���
		//��ջ��ַ��Ҫ�ı䣬�����ø��̵߳�
		uint sp = taskStruct.stackPtr;
		uc_reg_write(uc, UC_MIPS_REG_SP, sp);

		//����
		uint a0 = taskStruct.dataPtr;
		uc_reg_write(uc, UC_MIPS_REG_A0, a0);


		// ����߳�
		err = uc_emu_start(uc, entry, 0xFFFFFFFF, 0, 0);
		if (err != null)
		{
			Console.Write("Failed on uc_emu_start() with error returned: {0:D} ({1})\n", err, uc_strerror(err));
			Environment.Exit(1);
		}

		return 0;
	}
}